我正在开发仪器驱动程序,我想知道如何计算帧校验和.
说明:
@H_404_5@Expressed by characters [0-9] and [A-F].
Characters beginning from the character after [STX] and until [ETB] or
[ETX] (including [ETB] or [ETX]) are added in binary.The 2-digit numbers,which represent the least significant 8 bits in
hexadecimal code,are converted to ASCII characters [0-9] and [A-F].The most significant digit is stored in CHK1 and the least significant
digit in CHK2.
我没有超过第三和第四点.
可以为c#提供示例代码.
请帮帮我.
解决方法
@H_301_36@ 最后我得到答案,这里是计算校验和的代码:private string CalculateChecksum(string dataToCalculate) { byte[] byteToCalculate = Encoding.ASCII.GetBytes(dataToCalculate); int checksum = 0; foreach (byte chData in byteToCalculate) { checksum += chData; } checksum &= 0xff; return checksum.ToString("X2"); }