MODBUS RTU通信校验码的代码:

WORD GetCheckCode(const char * pSendBuf, int nEnd)
{
	WORD wCrc = WORD(0xFFFF);
	for(int i=0; i>= 1; 		
				wCrc ^= 0xA001; 	
			}
			else	
			{
				wCrc >>= 1; 
			}	
		}	
	}
	return wCrc;

}
WORD CRCCode = GetCheckCode((char*)szSend,6);
byte Code[2] = {0};
memcpy(Code,&CRCCode,sizeof(Code));

你可能感兴趣的:(个人兴趣)