我用VCU0下的getCRC16P1_vcu 程序计算CRC校验码,总是与modbus-RTU中CRC校验码不一致,不知道哪里出了问题。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
///<summary>
///
转换成CRC码
///</summary>
///<param
name="Array"></param>
///<param
name="Rcvbuf"></param>
///<param
name="Len"></param>
///<returns></returns>
//modbus CRC16
publicvoid
CRC16Calc(byte[]
dataBuff, int
dataLen)
{
int
CRCResult = 0xFFFF;
if
(dataLen < 2)
{
return;
}
for
(int
i = 0; i < (dataLen - 2); i++)
{
CRCResult = CRCResult ^ dataBuff[i];
for
(int
j = 0; j < 8; j++)
{
if
((CRCResult & 1) == 1)
CRCResult = (CRCResult >> 1) ^ 0xA001;
else
CRCResult >>= 1;
}
}
dataBuff[dataLen - 1] =Convert.ToByte(CRCResult
>> 8);
dataBuff[dataLen - 2] =Convert.ToByte(CRCResult
& 0xff);
}