Reputation: 378
I would like to calculate crc for the message to be sent to a dispenser. the message format is STX + DATA + ETX + CRC and it is written that "crc may be calulated by using AND operator between 7fh and sum of all characters including ETX, excluding STX or by using the OR operator between 40h and sum of all characters including ETX, excluding STX."
I couldn't get the format of the crc from this information.Any ideas or samples are welcomed,
Thank you for concern
Upvotes: 0
Views: 1094
Reputation: 16259
A byte with the ETX value will be 03. I'm assuming they mean you should add that to the sum of the values for the bytes in the data, and do a bitwise AND of that to 7F (hex). For example:
STX + "BYE" + ETX
would have a resulting value (in hex) of
(0x41 + 0x59 + 0x45 + 0x03) & 7f
which gives an answer of 0x62 (98 in decimal). Since the AND masks out all but the lowest 7 bits, I think you can safely ignore overflow. So, you would end up sending
STX + "BYE" + ETX + 0x62
Upvotes: 2