Modbus unsigned int 16

Hi Guys this is my first post, i have read all the post on modbus RTU and i have made a 95% there with the flows (8).json (398 Bytes)
flow just by reading and testing

The issue i have is the 16 bit true or false or 1 / 0, on my mode bus address 1015 there is 14 bits being used for the Error flag, what i would like to do is when i get bit 4 with true i want to change this to output "Error A12 (Sensor 2 Broken) so i can display this on the Dashboard,

What have i done Wrong?
Regards Dave

Here are 4 simple functions for bit manipulation:

It is safer to use those.

It would be easier for us, if you would export the whole Flow, so we can check out.
You have only exported 1 record with some values.

Thank you for the reply, all i want to do is have a lookup table for the fault code, at the moment i get 1 or 0

Please find attached the full flow

flows (9).json (18.3 KB)

Regards Dave

Hi PizzaProgram could you give me a example on your temple Regards Dave

Sorry, I don't understand.

sorry i mean this code, which part do i use to trigger a word for modbus,

I tend to use a set of functions that help me avoid typos... //Get bit function getBit(number, bitPosition) { return (number & (1 << bitPosition)) === 0 ? 0 : 1; } //Set Bit function setBit(number, bitPosition) { return number | (1 << bitPosition); } //Clear Bit function clearBit(number, bitPosition) { const mask = ~(1 << bitPosition); return number & mask; } //Update Bit function updateBit(number, bitPosition, bitValue) { const bitValueNormalized = bitValue ? 1 : 0; const clearM…

regards Dave

Those functions are not related to Modbus or Triggering.
Just help you to get/set 1-1 bit inside a number very fast.

What does that mean? What incoming values do you have in the payload and what do you want the payload to be set to by the function?

Screen Shot 2021-11-19 at 1.20.54 pm

Hi Colin

I have a modbus address which is a Unsigned Int 16 and i have used the 16 bit block in my flow which is called node-red-contrib-bit, what i would like to do is send a message so the ui dashboard that if the "true" message it will output the message "Alarm Fault" and if the message outputs false then it will output the message "Alarm Okay"

I hope this make more sense

Regards Dave

To convert the true/false state to the alarm strings you can use a Change node configured like this


[{"id":"dbed5f846f13f754","type":"change","z":"bdd7be38.d3b55","name":"Alarm string","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload  ?  \"Alarm Fault\"  :  \"Alarm OK\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1480,"wires":[["2ed65241d345c5e5"]]},{"id":"301c60703350d575","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":160,"y":1440,"wires":[["dbed5f846f13f754"]]},{"id":"226f750e4a7cdf6c","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":160,"y":1520,"wires":[["dbed5f846f13f754"]]},{"id":"2ed65241d345c5e5","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":1480,"wires":[]}]

Then to put it on the dashboard you can either send it to a Text node, or if you want a popup notification then use the Notification node.

Thank you Colin, that has been a god send thank you. it work's really well

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.