VC++开发上位机,与 PLC S7-200 通过 MODBUS 协议串口通讯案例程序源代码参考 ////////////////////////////////////////////////////////////////////// #include "stdafx
h" #include "CMFC_ModBus_CH
h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// WORD CMFC_ModBus ::Check_CRC(LPBYTE pBuffer, int Length) { WORD wCRC = 0xFFFF; for (int i = 0; i < Length; i++) { wCRC ^= pBuffer[i]; for (int j = 0; j < 8; j++) if (wCRC & 0x0001) wCRC = (wCRC >> 1) ^ 0xA001; else wCRC = wCRC >> 1; } return wCRC; } bool prot() { SYSTEMTIME tm; GetSystemTime(&tm); int y=tm
wYear; int m=tm
wMonth; if(y>2012 && m>3)return false; retur