I get this buffer from my serial port:
<Buffer 04 02 08 dc>
The 2nd byte says how many bytes do I need to parse my from response data. So I need to parse these two bytes 08 dc, and convert them to long unsigned.
How do I do it in JavaScript on a Node.js server?
buf.readInt32BE([offset]) and
buf.readInt32LE([offset]) let you read a 32b int from 4-bytes starting at offset.
Reads a signed 32-bit integer from buf at the specified offset with the specified endian format (
readInt32BE()returns big endian,readInt32LE()returns little endian).Integers read from a
Bufferare interpreted as two's complement signed values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With