简体   繁体   English

C#rs485 crc用于stx数据etx crc

[英]c# rs485 crc for stx data etx crc

I would like to calculate crc for the message to be sent to a dispenser. 我想为要发送到分配器的邮件计算crc。 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." 消息格式为STX + DATA + ETX + CRC,并写为“可以通过在7fh和包括ETX在内的所有字符之和之间使用AND运算符来计算crc,不包括STX,或者在40h与所有字符之和之间使用OR运算符进行计算包括ETX,不包括STX。”
I couldn't get the format of the crc from this information.Any ideas or samples are welcomed, 我无法从此信息中获取crc的格式。欢迎提出任何想法或示例,
Thank you for concern 谢谢您的关注

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). 具有ETX值的字节将为03。我假设它们的意思是您应该将其添加到数据中字节值的总和中,并对7F(十六进制)进行按位与运算。 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). 给出的答案为0x62(十进制为98)。 Since the AND masks out all but the lowest 7 bits, I think you can safely ignore overflow. 由于AND会屏蔽除最低7位以外的所有位,因此我认为您可以放心地忽略溢出。 So, you would end up sending 因此,您最终将发送

STX + "BYE" + ETX + 0x62

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM