Modbus TCP-node - (16 bits register neg number & 32 bit register reading)

2,467 views
Skip to first unread message

Luis GCU

unread,
Aug 23, 2016, 11:26:35 AM8/23/16
to Node-RED
Hello 
First of all  I want to say thanks to all the team and developers behind node-red, its simply a great idea and perfect tool for people like me that are not so advanced in high level programmings platform.
I am doing  several test with node-red so far  work great,  I just need more time reading and learning, very soon I will be posting some of those test project.

Just now I am testing  the   modbus TCP  Node communication  with AC-Servodrives , and the communication work fine , the only issue that I  have now is reading 16bits holding register when the value is negative the reading display is 65535, I also notice that I can't read 32 bits register using the offset, not sure is there is any workaround or just that  the modbus TCP node is not fully implemented at this point.
regards,

Julian Knight

unread,
Aug 23, 2016, 2:17:16 PM8/23/16
to Node-RED
This is where it helps to be old(er)! Since handling numbers at the bit level used to be common. You are treating the number as an unsigned integer rather than a signed one. The difference being that the most significant BIT in a signed number say whether the number is positive or negative. So you really have 15bits for the number and one for the sign.

Luis GCU

unread,
Aug 23, 2016, 3:17:36 PM8/23/16
to Node-RED
you right mate, the question is how should  I proceed to read a sint −32,768 to 32,767 - on node red modbus tcp node .. I don't see any  option to select sint  or int word. 
I use other HMI platform where you have those option .. but that node seems to do not have tha yet.. 
Thanks 

Julian Knight

unread,
Aug 23, 2016, 3:52:03 PM8/23/16
to Node-RED
Well, if the output is a buffer then node.js has some buffer read tools that would probably do the job for you: https://nodejs.org/api/buffer.html#buffer_buf_readint16be_offset_noassert

So maybe you could pass the buffer to a function node and then use the readint function to make sense of it?

Dave C-J

unread,
Aug 23, 2016, 6:08:54 PM8/23/16
to node...@googlegroups.com

Or talk nicely to the developer of the node... It does get updated fairly regularly.

Luis GCU

unread,
Aug 24, 2016, 8:43:54 AM8/24/16
to Node-RED
Thanks you guys for your advice,  I will try to follow Julian suggestions. 

Paul

unread,
Dec 2, 2017, 3:05:42 AM12/2/17
to Node-RED
Did you ever sort this out, I am having the same problem with a solar inverter

Paul

Luis GCU

unread,
Dec 2, 2017, 8:00:12 AM12/2/17
to Node-RED

Hello,
there is new modbus TCP  node  ( maybe not new but I notice  that one very recently) with that node  you can do a lot  manipulation with the buffer, I installed and tested sometime ago and it worked fine for me.. 

Hope this helps.

Leif Neland

unread,
Dec 2, 2017, 8:06:15 AM12/2/17
to Node-RED
I'm using the serial modbus, so I don't know if this is appliccable.

I read a 32 bit number, and then r=msg.payload.readUInt32BE(0)

So your 16 bit should be converted with msg.payload.readInt16BE (or readInt16LE)



[{"id":"b9fbecfb.dace4","type":"modbusSerial in","z":"cda43e91.58161","port":"54dc1f20.e61e3","slaves":"10","start":"286","count":"2","dtype":"holding","period":"5","topic":"Modbus","name":"B","x":105,"y":220,"wires":[["18bec1f8.7cdd5e"]]},{"id":"18bec1f8.7cdd5e","type":"function","z":"cda43e91.58161","name":"","func":"r=msg.payload.readUInt32BE(0)\nmsg.payload=r/100;\nreturn msg;","outputs":1,"noerr":0,"x":247,"y":217,"wires":[["a88dd1ad.36e6d"]]},{"id":"a88dd1ad.36e6d","type":"mqtt out","z":"cda43e91.58161","name":"","topic":"VarmeKWH","qos":"2","retain":"true","broker":"605c9cbd.0864b4","x":435.7869110107422,"y":223.58521270751953,"wires":[]},{"id":"54dc1f20.e61e3","type":"modbusSerialConfig","z":"","port":"/dev/modbus","baud":"2400","data":"8","parity":"even","stop":"1","name":""},{"id":"605c9cbd.0864b4","type":"mqtt-broker","z":"","broker":"192.168.1.254","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]
Reply all
Reply to author
Forward
0 new messages