SoftCRC16 类 |
命名空间: HslCommunication.Serial
SoftCRC16 类型公开以下成员。
名称 | 说明 | |
---|---|---|
CheckCRC16(Byte) |
来校验对应的接收数据的CRC校验码,默认多项式码为0xA001 To verify the CRC check code corresponding to the received data, the default polynomial code is 0xA001 | |
CheckCRC16(Byte, Byte, Byte) |
指定多项式码来校验对应的接收数据的CRC校验码 Specifies a polynomial code to validate the corresponding CRC check code for the received data | |
CRC16(Byte) |
获取对应的数据的CRC校验码,默认多项式码为0xA001 Get the CRC check code of the corresponding data, the default polynomial code is 0xA001 | |
CRC16(Byte, Byte, Byte, Byte, Byte) |
通过指定多项式码来获取对应的数据的CRC校验码 The CRC check code of the corresponding data is obtained by specifying the polynomial code | |
CRC16Only |
通过指定多项式码来获取对应的数据的CRC校验码 The CRC check code of the corresponding data is obtained by specifying the polynomial code | |
Equals | Determines whether the specified object is equal to the current object. (继承自 Object。) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (继承自 Object。) | |
GetHashCode | Serves as the default hash function. (继承自 Object。) | |
GetType | Gets the Type of the current instance. (继承自 Object。) | |
MemberwiseClone | Creates a shallow copy of the current Object. (继承自 Object。) | |
ToString | Returns a string that represents the current object. (继承自 Object。) |
名称 | 说明 | |
---|---|---|
ToJsonString |
获取当前对象的JSON格式表示的字符串。 (由 HslExtension 定义。)Gets the string represented by the JSON format of the current object. |
// 进行CRC校验,例如从modbus接收的数据 01 03 00 00 00 02 C4 0B bool check = HslCommunication.Serial.SoftCRC16.CheckCRC16( HslCommunication.BasicFramework.SoftBasic.HexStringToBytes( "01 03 00 00 00 02 C4 0B" ) ); if (check) { Console.WriteLine( "check success!" ); // 此处success } else { Console.WriteLine( "check failed!" ); } // 上述的代码是使用了多项式码 A0 01,检验成功,如果您的多项式不是这个,比如 B8 08 那么就需要按照如下的方式 check = HslCommunication.Serial.SoftCRC16.CheckCRC16( HslCommunication.BasicFramework.SoftBasic.HexStringToBytes( "01 03 00 00 00 02 C4 0B" ), 0xB8, 0x08 ); if (check) { Console.WriteLine( "check success!" ); } else { Console.WriteLine( "check failed!" ); // 此处failed }
// 计算CRC码,比如我要给"01 03 00 00 00 02"增加crc校验 byte[] buffer = HslCommunication.Serial.SoftCRC16.CRC16( HslCommunication.BasicFramework.SoftBasic.HexStringToBytes( "01 03 00 00 00 02" ) ); // buffer 就是 "01 03 00 00 00 02 C4 0B" 然后就可以发送到modbus的串口了 // 如果需要自己指定多项式码 B8 08 buffer = HslCommunication.Serial.SoftCRC16.CRC16( HslCommunication.BasicFramework.SoftBasic.HexStringToBytes( "01 03 00 00 00 02" ), 0xB8, 0x08 );