Hello guys ,
I want to use Node-Red to receive data from codesys via modbus tcp and then send to cloud using MQTT. The original data is a DINT (say -593) in codesys, I split it into two words to Modbus TCP (High word "FFFF" and low word "FDAF").
Now in Node-Red I have received two words in sequence and combined them to a DWORD "FFFFFDAF" , but after I use parseInt in JS I got the number 4294966703, instead of -593. I suppose it is converted into a 64-bit int rather then 32. How can I change it to a 32-bit int? Below is my convert code. Thank you for your support.
Zhiyao Yin
Node-Red Double Word to 32 bit Int Conversion
-
- Official 3rd Party Support Erminas
- Posts: 6
- Joined: 16 Mar 2022, 18:54
Re: Node-Red Double Word to 32 bit Int Conversion
Hello Zhiyao Yin,
basically, you would have to use the two's complement to convert the DWORD into Int.
To get around this, you can convert the result of parseInt() into 32-bit-int by forcing it with a binary operation. In this case, the or operation is always done by parseInt(), so this has no other effects. Regards
Dennis from Erminas
basically, you would have to use the two's complement to convert the DWORD into Int.
To get around this, you can convert the result of parseInt() into 32-bit-int by forcing it with a binary operation. In this case, the or operation is always done by parseInt(), so this has no other effects. Regards
Dennis from Erminas
Re: Node-Red Double Word to 32 bit Int Conversion
Got it. Thanks Dennis.dfilsinger-erminas wrote: ↑09 Nov 2022, 10:15 Hello Zhiyao Yin,
basically, you would have to use the two's complement to convert the DWORD into Int.
To get around this, you can convert the result of parseInt() into 32-bit-int by forcing it with a binary operation. In this case, the or operation is always done by parseInt(), so this has no other effects.
code.png
Regards
Dennis from Erminas