Answer the question
In order to leave comments, you need to log in
How to calculate the checksum of a package in C++?
I am programming in QT(C++) exchange with the device via serial port.
The device accepts data according to the ASTM 1381-95 protocol. Since I'm new to c++, I have some questions.
How to calculate the checksum of a sent packet?
If I make a request from the device, this type of packet comes up:
1H|\^&|||ACL9000|||||||P|1|2020
0210111653
87
2Q|1|ALL||||||||O
C4
3L|1|N
06
<STX>FN text<ETX>C1 C2<CR> <LF>
Answer the question
In order to leave comments, you need to log in
6.3.3.1 The checksum is initialized to zero with thecharacter.
The first character used in computing the checksum is the frame number. Each character in the message text is added to the checksum (modulo 256). The computation for the checksum does not include, the checksum characters, or the trailingand.
char frameNumber = ....;
char crc = frameNumber;
for (int i = 0; i < messageSize; ++i)
{
crc += message[i]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question