Y
Y
Yaroslav2021-11-29 21:28:31
Node.js
Yaroslav, 2021-11-29 21:28:31

How to convert custom command set for serialport (RS485) to bytes?

There is a physical piece of iron that accepts a set of commands. The exchange is carried out by ASCII characters.
From the documentation: "all bytes are transmitted as two ASCII characters with the high byte first. For example, the command "A" 34h,31h"
It is not clear how these character commands are translated into two bytes in nodejs. How to make from "A", for example, 0x34 0x31

And the checksum is considered as XOR for all characters up to the CRC field. Here is also a question. The same "A" is translated through charCodeAt (0) immediately into 65. I'm afraid the bitwise comparison will also be incorrect.

Basically, I'm asking for help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hint000, 2021-11-30
@YarkoDzech

Release, do not need links to the docks. I google and tell.
Modbus protocol.

How to make from "A", for example, 0x34 0x31
ASCII("A")=41h
Now "41" (without "h" suffix) is decomposed into two characters:
ASCII("4")=34h
ASCII("1")=31h
https://www.modbus.org/ docs/PI_MBUS_300.pdf
page 6;
and also about CRC, page 16.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question