// JB1506.cpp: implementation of the CJB1506 class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "JB1506.h" #include "CommProcess.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif int sentType = 1; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CJB1506::CJB1506( char szPath[MAX_PATH], // 程序所在路径 char szIniName[MAX_PATH], // 配置文件名称 int nCommPort, // 串行端口 int nAddr, // 设备地址 int nRate, // 波特率 int nDataBit, // 数据位 int nStopBit, // 停止位 int nParity, // 校验位 int nInterval // 时间间隔 ) { #if IS_USE_READMSG_CS InitializeCriticalSection( &m_csReadMsg ); //初始化一个临界资源对象 #endif MTVERIFY( m_hSemComm = CreateEvent( NULL, TRUE, TRUE, 0 ) ); //CreateEvent()创建或打开一个命名的或无名的事件对象 for( int i = 0; i < MAX_ADDR; i++ ) { memset(m_szJB1506_1Msg[i], 0, sizeof(m_szJB1506_1Msg[i])); memset(m_szJB1506_3Msg[i], 0, sizeof(m_szJB1506_3Msg[i])); m_devOnline[i] = TRUE; m_dwOnlineTick[i] = 0; } } CJB1506::~CJB1506() { #if IS_USE_READMSG_CS DeleteCriticalSection( &m_csReadMsg ); #endif MTVERIFY( CloseHandle( m_hSemComm ) ); CloseComm(); } BOOL CJB1506::JB1506OpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval) { BOOL bResult = FALSE; bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval ); return bResult; } int CJB1506::GetDeviceMsg(CCommProcess *pComm) { int nRet = 0; /************************************************************************/ /* SendMsg */ /************************************************************************/ BYTE getMsg[80]; memset(getMsg, 0, 80); //WaitForSingObject();等待有信号; if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) { //ResetEvent()设置无信号状态 ResetEvent( m_hSemComm ); int nResult = pComm->Read(getMsg, 3); int type = (int)(unsigned char)getMsg[1]; if (100 == type) { sentType = 0; } else if (101 == type) { sentType = 1; } //LOG4C((LOG_NOTICE,"getMsg = %s , sentType = %d ", getMsg, sentType)); //if( nResult != 7 ) { // //SetEvent设置有信号; // SetEvent( m_hSemComm ); // //返回 错误值; // return EER_CODE_UPSKEHUA_COM_REGNUM; //} } else{ //如果m_hSemCom无信号,返回错误; return ERR_CODE_JB1506_COM_BUSY; } /************************************************************************/ /* readfile ; */ /************************************************************************/ //int nRecvLen = 0; //BYTE pBuffer[270]; //memset(pBuffer, 0, 270); //nRecvLen = pComm->Read(pBuffer,270); SetEvent( m_hSemComm ); //LOG4C((LOG_NOTICE,"Authorization Sucess")); return 0; } // 发送读取设备参数请求 int CJB1506::SendReadRequest( char szPath[MAX_PATH], // 程序所在路径 char szIniName[MAX_PATH], // 配置文件名称 int nCommPort, // 串行端口 int nAddr, // 设备地址 char szCmd[MAX_CMD], // 请求命令 char szMsg[VAR_MSG], // 响应的值 int nReversed1, // 预留整形参数1接口 int nReversed2, // 预留整形参数2接口 int nReversed3, // 预留整形参数3接口 int nReversed4, // 预留整形参数4接口 int nReversed5, // 预留整形参数5接口 float fReversed1, // 预留float参数1接口 float fReversed2, // 预留float参数2接口 float fReversed3, // 预留float参数3接口 char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口 char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口 char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口 char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口 char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口 ) { int nIndex = 0, nLen = 0, StaBit = 0, EndBit = 0; char szSendMsg[JB1506_SEND_MSG]; char szType[TYPE_LENGTH] = {0}; char szCid2[CID2_LENGTH] = {0}; int type = 0; int start = 254; int eol = 255; CCommProcess *pComm = FindComm(nCommPort); GetDeviceMsg(pComm); if( pComm == NULL ) return -1; memset(szSendMsg, 0, JB1506_SEND_MSG); memset(szMsg, 0, VAR_MSG); GetFromIni(szPath, szIniName, szCmd, szCid2, type, nIndex, nLen, StaBit, EndBit); szSendMsg[0] = start; if (0 == sentType) { szSendMsg[1] = (type+10); } else if (1 == sentType) { szSendMsg[1] = type; } szSendMsg[2] = eol; int nRet = -1; if( nAddr < 1 ) return -1; if( ( strlen(m_szJB1506_1Msg[nAddr-1]) == 0 && ( strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 || strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 || strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ) ) || strcmp(szCmd, "cmd-2") == 0 ) { nRet = GetDeviceParam( pComm, nAddr, szSendMsg, szCmd, szMsg, nIndex, nLen, szType ); if( nRet != 0 ) { return nRet; } } if( GetTickCount() - m_dwOnlineTick[nAddr - 1] > 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 ) { m_devOnline[nAddr - 1] = FALSE; } else if( GetTickCount() - m_dwOnlineTick[nAddr - 1] < 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 ) { m_devOnline[nAddr - 1] = TRUE; } if( m_devOnline[nAddr - 1] == FALSE ) { return -1; } nRet = GetJB1506_1VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType); //LOG4C((LOG_NOTICE,"szCmd = %s ,返回值 = %s ",szCmd, szMsg)); return nRet; } int CJB1506::GetJB1506_1VarMsg( int nAddr, char szCmd[MAX_CMD], // 命令 char szMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH] // 变量数据类型 ) { int nRet = 0; if( strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 || strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 || strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(szMsg, m_szJB1506_1Msg[nAddr - 1] + nIndex, nLen); //DataConversion(szType, m_szJB1506_1Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); //LOG4C((LOG_NOTICE," szMsg = %s ,MSG = %s ",szMsg, m_szJB1506_1Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CJB1506::GetJB1506_3VarMsg( int nAddr, char szCmd[MAX_CMD], // 命令 char szMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH] // 变量数据类型 ) { int nRet = 0; if(strcmp(szCmd, "cmd-1") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif //memcpy(szMsg, m_szJB1506_3Msg + nIndex, nLen); DataConversion(szType, m_szJB1506_3Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CJB1506::GetDeviceParam( CCommProcess *pComm, //串口对象指针 int nAddr, char szSendMsg[JB1506_SEND_MSG], //发送Buffer char szCmd[MAX_CMD], // 命令 char szMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH]) // 变量数据类型 { int nRet = -1; nRet = RequestStatus(szCmd, pComm, szSendMsg); if( nRet != 0 ) { return nRet; // 串口忙 } nRet = ResponseStatus(pComm, nAddr, szCmd, szMsg, nIndex, nLen, szType); return nRet; } int CJB1506::SetDeviceParam( CCommProcess *pComm, //串口对象指针 int nAddr, char szSendMsg[JB1506_SEND_MSG], //发送Buffer char szCmd[MAX_CMD], // 命令 char szMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH]) // 变量数据类型 { int nRet = -1; nRet = WriteRequestStatus(szCmd, pComm, szSendMsg); if( nRet != 0 ) { return nRet; // 串口忙 } nRet = WriteResponseStatus(pComm, nAddr, szCmd, szMsg, nIndex, nLen, szType); return nRet; } void CJB1506::SetJB1506_1VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer) { if(strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 || strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 || strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szJB1506_1Msg[nAddr - 1], pBuffer, sizeof(m_szJB1506_1Msg[nAddr - 1])); //LOG4C((LOG_NOTICE," pBuffer = %s ,MSG = %s ",pBuffer, m_szJB1506_1Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CJB1506::SetJB1506_3VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer) { if( strcmp(szCmd, "cmd-1") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szJB1506_3Msg[nAddr - 1], pBuffer, sizeof(m_szJB1506_3Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } WORD CJB1506::GetDataLength(const WORD wLENID, char chLength[4]) { char szLenID[3] = {0}; //int nLen = 10; DigitToBinary(wLENID, szLenID, sizeof(szLenID)); char chCheckSum = GetLCheckSum(szLenID, sizeof(szLenID)); chLength[0] = chCheckSum; chLength[1] = szLenID[0]; chLength[2] = szLenID[1]; chLength[3] = szLenID[2]; return 0; } char CJB1506::GetLCheckSum(char *pBuf, int len) { //WORD iSum = 0; char chCompliment = 0; //unsigned char chCompliment[2] = {0}; for(int i=0; iWrite((unsigned char *)chSendMsg, nDataLen); if( nResult == nDataLen ) { nRet = 0; } else { SetEvent( m_hSemComm ); return ERR_CODE_JB1506_COM_INVALIDRES; } } else { return ERR_CODE_JB1506_COM_BUSY; } #endif return nRet; } int CJB1506::ResponseStatus( CCommProcess *pComm, //串口对象指针 int nAddr, // 设备地址 char szCmd[MAX_CMD], // 命令 char szMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH] // 变量数据类型 ) { #if DEBUG_JB1506 int nReceiveLen = 0; int nProcessLen = 0; int nReadLen = 0; //RESPONSE_STRUCT structResponse; //memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) ); nReceiveLen = JB1506_RECEIVE_MSG; char *pBuffer = new char[ nReceiveLen ]; memset(pBuffer, 0, nReceiveLen); nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen); if( nReadLen <= 0) { // 串口没有读到数据 //TRACE("串口没有读到数据!\r\n"); //AfxMessageBox("串口没有读到数据!"); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_JB1506_COM_READ_NO_DATA; } //int nTempLen = strlen(pBuffer); //CString str; //str.Format("%d", nTempLen); //AfxMessageBox(str); //if (!ChkSumCheck(pBuffer, (int)strlen(pBuffer))) //{ // // 校检错误 // //AfxMessageBox("校检错误"); // //TRACE("校检错误!\r\n"); // SetEvent( m_hSemComm ); // if( pBuffer != NULL) // { // delete[] pBuffer; // pBuffer = NULL; // } // return ERR_CODE_JB1506_COM_CHKSUM_LOST; //} //if (!CheckLength(pBuffer)) //{ // // 数据长度校检错误 // //TRACE("数据长度校检错误!\r\n"); // //AfxMessageBox("数据长度校检错误!"); // SetEvent( m_hSemComm ); // if( pBuffer != NULL) // { // delete[] pBuffer; // pBuffer = NULL; // } // return ERR_CODE_JB1506_COM_VARLEN; //} //int nRet = RtnCheck(pBuffer); //if(0 != nRet) //{ // //AfxMessageBox("校验出错"); // // 设置串口等待事件为有信号 // SetEvent( m_hSemComm ); // if( pBuffer != NULL) // { // delete[] pBuffer; // pBuffer = NULL; // } // return nRet; //} char szStr[60]; memset(szStr, 0, 60); memcpy(szStr, pBuffer, strlen(pBuffer)); int type = (int)(unsigned char)szStr[1]; int alarmNum = (int)(unsigned char)szStr[2]; BYTE szGetMsg[60]; memcpy(szGetMsg,"0000000000000000000000000000000000000000000.",sizeof("0000000000000000000000000000000000000000000.")); szGetMsg[0] = 254; if (100 == type) { sentType = 0; } else if (101 == type) { sentType = 1; } else if (1 == type) { szGetMsg[1] = 49; szGetMsg[2] = alarmNum + 48; for (int i=3; i< (alarmNum+3); i++) { int ctrlNum = (int)(unsigned char)szStr[i]; szGetMsg[ctrlNum+2] = '1'; } //LOG4C((LOG_NOTICE," pBuffer = %s ,szGetMsg = %s ",pBuffer, szGetMsg)); } else if (2 == type) { szGetMsg[1] = 50; szGetMsg[2] = alarmNum + 48; for (int i=3; i< (alarmNum+3); i++) { int ctrlNum = (int)(unsigned char)szStr[i]; szGetMsg[ctrlNum+2] = '2'; } } SetJB1506_1VarMsg(nAddr, szCmd, (char*)szGetMsg); //LOG4C((LOG_NOTICE," pBuffer = %s ,szGetMsg = %s ",pBuffer, szGetMsg)); m_dwOnlineTick[nAddr - 1] = GetTickCount(); // 设置串口等待事件为有信号 SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } #else SimulationCommData(); #endif return 0; } int CJB1506::WriteRequestStatus( char szCmd[MAX_CMD], // 命令 CCommProcess *pComm, //串口对象指针 char chSendMsg[JB1506_SEND_MSG] //发送Buffer ) { #if DEBUG_JB1506 int nDataLen = (int)strlen(chSendMsg); ResetEvent( m_hSemComm ); int nResult = pComm->Write((unsigned char *)chSendMsg, nDataLen); if( nResult == nDataLen ) { } else { SetEvent( m_hSemComm ); return EER_CODE_JB1506_COM_WRITE_DATA; } #endif return 0; } int CJB1506::WriteResponseStatus( CCommProcess *pComm, //串口对象指针 int nAddr, // 设备地址 char szCmd[MAX_CMD], // 命令 char szMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH] // 变量数据类型 ) { #if DEBUG_JB1506 int nReceiveLen = 0; int nProcessLen = 0; int nReadLen = 0; //RESPONSE_STRUCT structResponse; //memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) ); nReceiveLen = JB1506_RECEIVE_MSG; char *pBuffer = new char[ nReceiveLen ]; memset(pBuffer, 0, nReceiveLen); nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen); if( nReadLen <= 0) { // 串口没有读到数据 //TRACE("串口没有读到数据!\r\n"); //AfxMessageBox("串口没有读到数据!"); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_JB1506_COM_READ_NO_DATA; } #if 0 //int nTempLen = strlen(pBuffer); //CString str; //str.Format("%d", nTempLen); //AfxMessageBox(str); if (!ChkSumCheck(pBuffer, strlen(pBuffer))) { // 校检错误 //AfxMessageBox("校检错误"); //TRACE("校检错误!\r\n"); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_JB1506_COM_CHKSUM_LOST; } if (!CheckLength(pBuffer)) { // 数据长度校检错误 //TRACE("数据长度校检错误!\r\n"); //AfxMessageBox("数据长度校检错误!"); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_JB1506_COM_VARLEN; } int nRet = RtnCheck(pBuffer); if(0 != nRet) { //AfxMessageBox("校验出错"); // 设置串口等待事件为有信号 SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return nRet; } #endif // 设置串口等待事件为有信号 SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } #else SimulationCommData(); #endif return 0; } void CJB1506::SimulationCommData(void) { /*cid2 =42 :7E 32 31 30 31 36 30 30 30 34 30 30 43 30 30 44 45 30 32 42 43 30 30 30 30 46 42 30 46 0D */ #if 0 m_szJB1506_1Msg[0] = 0x7E; m_szJB1506_1Msg[1] = 0x32; m_szJB1506_1Msg[2] = 0x31; m_szJB1506_1Msg[3] = 0x30; m_szJB1506_1Msg[4] = 0x31; m_szJB1506_1Msg[5] = 0x36; m_szJB1506_1Msg[6] = 0x30; m_szJB1506_1Msg[7] = 0x30; m_szJB1506_1Msg[8] = 0x30; m_szJB1506_1Msg[9] = 0x34; m_szJB1506_1Msg[10] = 0x30; m_szJB1506_1Msg[11] = 0x30; m_szJB1506_1Msg[12] = 0x43; m_szJB1506_1Msg[13] = 0x30; m_szJB1506_1Msg[14] = 0x30; m_szJB1506_1Msg[15] = 0x44; m_szJB1506_1Msg[16] = 0x45; m_szJB1506_1Msg[17] = 0x30; m_szJB1506_1Msg[18] = 0x32; m_szJB1506_1Msg[19] = 0x42; m_szJB1506_1Msg[20] = 0x43; m_szJB1506_1Msg[21] = 0x30; m_szJB1506_1Msg[22] = 0x30; m_szJB1506_1Msg[23] = 0x30; m_szJB1506_1Msg[24] = 0x30; m_szJB1506_1Msg[25] = 0x46; m_szJB1506_1Msg[26] = 0x42; m_szJB1506_1Msg[27] = 0x30; m_szJB1506_1Msg[28] = 0x46; m_szJB1506_1Msg[29] = 0x0D; /*cid2 = 82:7E 32 31 30 31 36 30 30 30 34 30 30 43 30 31 32 37 30 30 30 30 30 30 30 30 46 42 35 35 0D */ m_szJB1506_82Msg[0] = 0x7E; m_szJB1506_82Msg[1] = 0x32; m_szJB1506_82Msg[2] = 0x31; m_szJB1506_82Msg[3] = 0x30; m_szJB1506_82Msg[4] = 0x31; m_szJB1506_82Msg[5] = 0x36; m_szJB1506_82Msg[6] = 0x30; m_szJB1506_82Msg[7] = 0x30; m_szJB1506_82Msg[8] = 0x30; m_szJB1506_82Msg[9] = 0x34; m_szJB1506_82Msg[10] = 0x30; m_szJB1506_82Msg[11] = 0x30; m_szJB1506_82Msg[12] = 0x43; m_szJB1506_82Msg[13] = 0x30; m_szJB1506_82Msg[14] = 0x31; m_szJB1506_82Msg[15] = 0x32; m_szJB1506_82Msg[16] = 0x37; m_szJB1506_82Msg[17] = 0x30; m_szJB1506_82Msg[18] = 0x30; m_szJB1506_82Msg[19] = 0x30; m_szJB1506_82Msg[20] = 0x30; m_szJB1506_82Msg[21] = 0x30; m_szJB1506_82Msg[22] = 0x30; m_szJB1506_82Msg[23] = 0x30; m_szJB1506_82Msg[24] = 0x30; m_szJB1506_82Msg[25] = 0x46; m_szJB1506_82Msg[26] = 0x42; m_szJB1506_82Msg[27] = 0x35; m_szJB1506_82Msg[28] = 0x35; m_szJB1506_82Msg[29] = 0x0D; /*cid2 = 47:7E 32 31 30 31 36 30 30 30 35 30 31 41 30 30 30 30 30 30 30 30 30 30 46 41 30 30 31 45 30 32 35 38 30 30 36 34 30 30 46 38 36 39 0D*/ m_szJB1506_7Msg[0] = 0x7E; m_szJB1506_7Msg[1] = 0x32; m_szJB1506_7Msg[2] = 0x31; m_szJB1506_7Msg[3] = 0x30; m_szJB1506_7Msg[4] = 0x31; m_szJB1506_7Msg[5] = 0x36; m_szJB1506_7Msg[6] = 0x30; m_szJB1506_7Msg[7] = 0x30; m_szJB1506_7Msg[8] = 0x30; m_szJB1506_7Msg[9] = 0x35; m_szJB1506_7Msg[10] = 0x30; m_szJB1506_7Msg[11] = 0x31; m_szJB1506_7Msg[12] = 0x41; m_szJB1506_7Msg[13] = 0x30; m_szJB1506_7Msg[14] = 0x30; m_szJB1506_7Msg[15] = 0x30; m_szJB1506_7Msg[16] = 0x30; m_szJB1506_7Msg[17] = 0x30; m_szJB1506_7Msg[18] = 0x30; m_szJB1506_7Msg[19] = 0x30; m_szJB1506_7Msg[20] = 0x30; m_szJB1506_7Msg[21] = 0x30; m_szJB1506_7Msg[22] = 0x30; m_szJB1506_7Msg[23] = 0x46; m_szJB1506_7Msg[24] = 0x41; m_szJB1506_7Msg[25] = 0x30; m_szJB1506_7Msg[26] = 0x30; m_szJB1506_7Msg[27] = 0x31; m_szJB1506_7Msg[28] = 0x45; m_szJB1506_7Msg[29] = 0x30; m_szJB1506_7Msg[30] = 0x32; m_szJB1506_7Msg[31] = 0x35; m_szJB1506_7Msg[32] = 0x38; m_szJB1506_7Msg[33] = 0x30; m_szJB1506_7Msg[34] = 0x30; m_szJB1506_7Msg[35] = 0x36; m_szJB1506_7Msg[36] = 0x34; m_szJB1506_7Msg[37] = 0x30; m_szJB1506_7Msg[38] = 0x30; m_szJB1506_7Msg[39] = 0x46; m_szJB1506_7Msg[40] = 0x38; m_szJB1506_7Msg[41] = 0x36; m_szJB1506_7Msg[42] = 0x39; m_szJB1506_7Msg[43] = 0x0D; //m_szJB1506_41Msg[44] = 0x42; //m_szJB1506_41Msg[45] = 0x34; //m_szJB1506_41Msg[46] = 0x33; //m_szJB1506_41Msg[47] = 0x30; //m_szJB1506_41Msg[48] = 0x30; //m_szJB1506_41Msg[49] = 0x30; //m_szJB1506_41Msg[50] = 0x30; //m_szJB1506_41Msg[51] = 0x35; //m_szJB1506_41Msg[52] = 0x42; //m_szJB1506_41Msg[53] = 0x34; //m_szJB1506_41Msg[54] = 0x33; //m_szJB1506_41Msg[55] = 0x30; //m_szJB1506_41Msg[56] = 0x30; //m_szJB1506_41Msg[57] = 0x30; //m_szJB1506_41Msg[58] = 0x30; //m_szJB1506_41Msg[59] = 0x35; //m_szJB1506_41Msg[60] = 0x42; //m_szJB1506_41Msg[61] = 0x34; //m_szJB1506_41Msg[62] = 0x33; //m_szJB1506_41Msg[63] = 0x30; //m_szJB1506_41Msg[64] = 0x30; //m_szJB1506_41Msg[65] = 0x30; //m_szJB1506_41Msg[66] = 0x30; //m_szJB1506_41Msg[67] = 0x32; //m_szJB1506_41Msg[68] = 0x30; //m_szJB1506_41Msg[69] = 0x34; //m_szJB1506_41Msg[70] = 0x31; //m_szJB1506_41Msg[71] = 0x30; //m_szJB1506_41Msg[72] = 0x30; //m_szJB1506_41Msg[73] = 0x30; //m_szJB1506_41Msg[74] = 0x30; //m_szJB1506_41Msg[75] = 0x32; //m_szJB1506_41Msg[76] = 0x30; //m_szJB1506_41Msg[77] = 0x34; //m_szJB1506_41Msg[78] = 0x31; //m_szJB1506_41Msg[79] = 0x30; //m_szJB1506_41Msg[80] = 0x30; //m_szJB1506_41Msg[81] = 0x30; //m_szJB1506_41Msg[82] = 0x30; //m_szJB1506_41Msg[83] = 0x32; //m_szJB1506_41Msg[84] = 0x30; //m_szJB1506_41Msg[85] = 0x34; //m_szJB1506_41Msg[86] = 0x31; //m_szJB1506_41Msg[87] = 0x30; //m_szJB1506_41Msg[88] = 0x30; //m_szJB1506_41Msg[89] = 0x30; //m_szJB1506_41Msg[90] = 0x30; //m_szJB1506_41Msg[91] = 0x31; //m_szJB1506_41Msg[92] = 0x30; //m_szJB1506_41Msg[93] = 0x34; //m_szJB1506_41Msg[94] = 0x31; //m_szJB1506_41Msg[95] = 0x30; //m_szJB1506_41Msg[96] = 0x30; //m_szJB1506_41Msg[97] = 0x38; //m_szJB1506_41Msg[98] = 0x30; //m_szJB1506_41Msg[99] = 0x30; //m_szJB1506_41Msg[100] = 0x39; //m_szJB1506_41Msg[101] = 0x34; //m_szJB1506_41Msg[102] = 0x35; //m_szJB1506_41Msg[103] = 0x30; //m_szJB1506_41Msg[104] = 0x30; //m_szJB1506_41Msg[105] = 0x30; //m_szJB1506_41Msg[106] = 0x30; //m_szJB1506_41Msg[107] = 0x30; //m_szJB1506_41Msg[108] = 0x30; //m_szJB1506_41Msg[109] = 0x45; //m_szJB1506_41Msg[110] = 0x30; //m_szJB1506_41Msg[111] = 0x31; //m_szJB1506_41Msg[112] = 0x38; //m_szJB1506_41Msg[113] = 0x0D; //m_szJB1506_41Msg[114] = 0x39; //m_szJB1506_41Msg[115] = 0x2E; //m_szJB1506_41Msg[116] = 0x30; //m_szJB1506_41Msg[117] = 0x20; //m_szJB1506_41Msg[118] = 0x33; //m_szJB1506_41Msg[119] = 0x35; //m_szJB1506_41Msg[110] = 0x2E; //m_szJB1506_41Msg[121] = 0x35; //m_szJB1506_41Msg[122] = 0x20; //m_szJB1506_41Msg[123] = 0x4C; //m_szJB1506_41Msg[124] = 0x4D; //m_szJB1506_41Msg[125] = 0x0D; //m_szJB1506_41Msg[126] = 0x32; //m_szJB1506_41Msg[127] = 0x0D; #endif } //char *CJB1506::GetChkSum(char Msg[VAR_MSG]) //{ // WORD iMsg; // char iChk[4]; // int len; // // len = sizeof(Msg); //取出数据长度 lenID/2 // // iMsg = 0; // for (int i=1;i<=(len-6);i++) // { // iMsg += Msg[i]; //ASSIC码值相加 // } // iMsg = iMsg%65536; // iMsg = ~iMsg + 1; // // itoa(iMsg,iChk,16); // // return iChk; //} // //BOOL CJB1506::ChkSumCheck(char Msg[VAR_MSG]) //{ // WORD iMsg; // char iChk[4]; // int len; // // len = sizeof(Msg); //取出数据长度 lenID/2 // // iMsg = 0; // for (int i=1;i<=(len-6);i++) // { // iMsg += Msg[i]; //ASSIC码值相加 // } // iMsg = iMsg%65536; // iMsg = ~iMsg + 1; // // itoa(iMsg,iChk,16); // // if ((lowercase2uppercase(iChk[0])==Msg[len-5]) && (lowercase2uppercase(iChk[1]) == Msg[len-4]) // && (lowercase2uppercase(iChk[2]) == Msg[len-3]) && (lowercase2uppercase(iChk[3]) == Msg[len-2])) // { // return TRUE; // } // else // { // return FALSE; // } //} // //BOOL CJB1506::CheckLength(char Msg[VAR_MSG]) //{ // WORD len ,index , lenID; // len = 4; // index = 9; // char ch[4]; // // for (int i=0;i