#include "stdafx.h" #include "JB1501A64P.h" #include "CommProcess.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif CJB1501A64P::CJB1501A64P( 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_szJB1501A64P_1Msg[i], 0, sizeof(m_szJB1501A64P_1Msg[i])); memset(m_szJB1501A64P_3Msg[i], 0, sizeof(m_szJB1501A64P_3Msg[i])); memset(m_szJB1501A64P_7Msg[i], 0, sizeof(m_szJB1501A64P_7Msg[i])); m_devOnline[i] = TRUE; m_dwOnlineTick[i] = 0; } } CJB1501A64P::~CJB1501A64P() { #if IS_USE_READMSG_CS DeleteCriticalSection( &m_csReadMsg ); #endif MTVERIFY( CloseHandle( m_hSemComm ) ); CloseComm(); } BOOL CJB1501A64P::JB1501A64POpenComm(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 CJB1501A64P::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[JB1501A64P_SEND_MSG]; char szType[TYPE_LENGTH] = {0}; char szCid2[CID2_LENGTH] = {0}; int type = 0; int eol = 255; memset(szSendMsg, 0, JB1501A64P_SEND_MSG); memset(szMsg, 0, VAR_MSG); GetFromIni(szPath, szIniName, szCmd, szCid2, type, nIndex, nLen, StaBit, EndBit); szSendMsg[0] = nAddr; szSendMsg[1] = type; szSendMsg[2] = eol; CCommProcess *pComm = FindComm(nCommPort); if( pComm == NULL ) return -1; int nRet = -1; if( nAddr < 1 ) return -1; if( ( strlen(m_szJB1501A64P_1Msg[nAddr-1]) == 0 && ( strcmp(szCmd, "cmd-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-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 || strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 || strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 || strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 )) || ( strlen(m_szJB1501A64P_7Msg[nAddr-1]) == 0 && ( strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 ) ) ||strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-11") == 0 ||strcmp(szCmd, "cmd-14") == 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 = GetJB1501A64P_1VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType); nRet = GetJB1501A64P_7VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType); //LOG4C((LOG_NOTICE,"szCmd = %s ,返回值 = %s ",szCmd, szMsg)); return nRet; } int CJB1501A64P::GetJB1501A64P_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-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-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-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 || strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 || strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 || strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(szMsg, m_szJB1501A64P_1Msg[nAddr - 1] + nIndex, nLen); //DataConversion(szType, m_szJB1501A64P_1Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CJB1501A64P::GetJB1501A64P_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-10") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif //memcpy(szMsg, m_szJB1501A64P_3Msg + nIndex, nLen); DataConversion(szType, m_szJB1501A64P_3Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CJB1501A64P::GetJB1501A64P_7VarMsg( 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-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif //memcpy(szMsg, m_szJB1501A64P_7Msg + nIndex, nLen); DataConversion(szType, m_szJB1501A64P_7Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CJB1501A64P::GetDeviceParam( CCommProcess *pComm, //串口对象指针 int nAddr, char szSendMsg[JB1501A64P_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,szSendMsg ,szCmd, szMsg, nIndex, nLen, szType); return nRet; } int CJB1501A64P::SetDeviceParam( CCommProcess *pComm, //串口对象指针 int nAddr, char szSendMsg[JB1501A64P_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 CJB1501A64P::SetJB1501A64P_1VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer) { if( strcmp(szCmd, "cmd-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-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-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 || strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 || strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 || strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szJB1501A64P_1Msg[nAddr - 1], pBuffer, sizeof(m_szJB1501A64P_1Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CJB1501A64P::SetJB1501A64P_3VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer) { if( strcmp(szCmd, "cmd-10") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szJB1501A64P_3Msg[nAddr - 1], pBuffer, sizeof(m_szJB1501A64P_3Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CJB1501A64P::SetJB1501A64P_7VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer) { if(strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szJB1501A64P_7Msg[nAddr - 1], pBuffer, sizeof(m_szJB1501A64P_7Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } WORD CJB1501A64P::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 CJB1501A64P::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 ) { ; } else { SetEvent( m_hSemComm ); return ERR_CODE_JB1501A64P_COM_INVALIDRES; } } else { return ERR_CODE_JB1501A64P_COM_BUSY; } #endif return 0; } int CJB1501A64P::ResponseStatus( CCommProcess *pComm, //串口对象指针 int nAddr, // 设备地址 char szSendMsg[JB1501A64P_SEND_MSG], char szCmd[MAX_CMD], // 命令 char szMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH] // 变量数据类型 ) { #if DEBUG_JB1501A64P int nReceiveLen = 0; int nProcessLen = 0; int nReadLen = 0; nReceiveLen = JB1501A64P_RECEIVE_MSG; char *pBuffer = new char[ nReceiveLen ]; memset(pBuffer, 0, nReceiveLen); nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen); if( nReadLen <= 0) { SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_JB1501A64P_COM_READ_NO_DATA; } if ( szSendMsg[1] == 100) { int type = pBuffer[1] ; int alarmNum = pBuffer[2] ; char szGetMsg[100] = {0}; memcpy(szGetMsg,"10<000000000000000000000000000000000000000000000000000000000000000000.",sizeof("10<000000000000000000000000000000000000000000000000000000000000000000.")); if (0 == type) { for(int j=0; j < 6; j++) szGetMsg[63+j] = pBuffer[2 + j] + 48; //if ( pBuffer[2 + j] == 0x07 ) //szGetMsg[63+j] = '7'; //LOG4C((LOG_NOTICE," 正常情况 ")); } else if (1 == type) { szGetMsg[1] = 49; szGetMsg[2] = alarmNum +48; for (int i=3; i< (alarmNum + 3); i++) { int ctrlNum = (unsigned char)pBuffer[i]; szGetMsg[ctrlNum+2] = '1'; } for(int j = 0; j < 6; j ++) { szGetMsg[63+j] = pBuffer[alarmNum+3+j] + 48; } //LOG4C((LOG_NOTICE," 火警情况 ")); } else if (2 == type) { szGetMsg[1] = 50; szGetMsg[2] = alarmNum +48; for (int i=3; i< (alarmNum + 3); i++) { int ctrlNum = (int)(unsigned char)pBuffer[i]; szGetMsg[ctrlNum+2] = '2'; } for(int j=0; j<6; j++) { szGetMsg[alarmNum+3+j] = pBuffer[alarmNum+3+j] + 48; } //LOG4C((LOG_NOTICE," 故障情况 ")); } //LOG4C_HEX_DUMP((LOG_NOTICE, pBuffer, sizeof(pBuffer))); memset(pBuffer,0,sizeof(pBuffer)); memcpy(pBuffer,szGetMsg,sizeof(szGetMsg)); SetJB1501A64P_1VarMsg(nAddr, szCmd, pBuffer); } else SetJB1501A64P_7VarMsg(nAddr, szCmd, pBuffer); m_dwOnlineTick[nAddr - 1] = GetTickCount(); // 设置串口等待事件为有信号; SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } #else SimulationCommData(); #endif return 0; } int CJB1501A64P::WriteRequestStatus( char szCmd[MAX_CMD], // 命令 CCommProcess *pComm, //串口对象指针 char chSendMsg[JB1501A64P_SEND_MSG] //发送Buffer ) { #if DEBUG_JB1501A64P 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_JB1501A64P_COM_WRITE_DATA; } #endif return 0; } int CJB1501A64P::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_JB1501A64P int nReceiveLen = 0; int nProcessLen = 0; int nReadLen = 0; nReceiveLen = JB1501A64P_RECEIVE_MSG; char *pBuffer = new char[ nReceiveLen ]; memset(pBuffer, 0, nReceiveLen); nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen); if( nReadLen <= 0) { SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_JB1501A64P_COM_READ_NO_DATA; } // 设置串口等待事件为有信号 SetEvent( m_hSemComm ); if( pBuffer != NULL){ delete[] pBuffer; pBuffer = NULL; } #else SimulationCommData(); #endif return 0; } void CJB1501A64P::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 */ BYTE pBuffer[70] = {0}; pBuffer[0] = 0x01 ; pBuffer[1] = 0x01 ; pBuffer[2] = 0x07 ; pBuffer[3] = 0x01 ; pBuffer[4] = 0x02 ; pBuffer[5] = 0x03 ; pBuffer[6] = 0x04 ; pBuffer[7] = 0x05 ; pBuffer[8] = 0x06 ; pBuffer[9] = 0x07 ; pBuffer[10] = 0x37 ; pBuffer[11] = 0x37 ; pBuffer[12] = 0x37 ; pBuffer[13] = 0x37 ; pBuffer[14] = 0x30 ; pBuffer[15] = 0x30 ; pBuffer[16] = 0x30 ; pBuffer[17] = 0x30 ; pBuffer[18] = 0x30 ; pBuffer[19] = 0x30 ; pBuffer[20] = 0x30 ; pBuffer[21] = 0x30 ; pBuffer[22] = 0x30 ; pBuffer[23] = 0x30 ; pBuffer[24] = 0x30 ; pBuffer[25] = 0x30 ; pBuffer[26] = 0x30 ; pBuffer[27] = 0x30 ; pBuffer[28] = 0x30 ; pBuffer[29] = 0x30 ; pBuffer[30] = 0x30 ; pBuffer[31] = 0x30 ; pBuffer[32] = 0x30 ; pBuffer[33] = 0x30 ; pBuffer[34] = 0x30 ; pBuffer[35] = 0x30 ; pBuffer[36] = 0x30 ; pBuffer[37] = 0x30 ; pBuffer[38] = 0x30 ; pBuffer[39] = 0x30 ; pBuffer[40] = 0x30 ; pBuffer[41] = 0x30 ; pBuffer[42] = 0x30 ; pBuffer[43] = 0x30 ; pBuffer[44] = 0x30 ; pBuffer[45] = 0x30 ; pBuffer[46] = 0x30 ; pBuffer[47] = 0x30 ; pBuffer[48] = 0x30 ; pBuffer[49] = 0x30 ; pBuffer[50] = 0x30 ; pBuffer[51] = 0x30 ; pBuffer[52] = 0x30 ; pBuffer[53] = 0x30 ; pBuffer[54] = 0x30 ; pBuffer[55] = 0x30 ; pBuffer[56] = 0x30 ; pBuffer[57] = 0x30 ; pBuffer[58] = 0x30 ; pBuffer[59] = 0x30 ; pBuffer[60] = 0x30 ; pBuffer[61] = 0x30 ; pBuffer[62] = 0x30 ; pBuffer[63] = 0x07 ; pBuffer[64] = 0x07 ; pBuffer[65] = 0x07 ; pBuffer[66] = 0x07 ; pBuffer[67] = 0x07 ; pBuffer[68] = 0x07 ; pBuffer[69] = 0xFF ; int type = pBuffer[1] ; int alarmNum = pBuffer[2] ; char szGetMsg[100] = {0}; memcpy(szGetMsg,"10<000000000000000000000000000000000000000000000000000000000000000000.",sizeof("10<000000000000000000000000000000000000000000000000000000000000000000.")); if (0 == type) { for(int j=0; j < 6; j++) { if ( pBuffer[2 + j] == 0x07 ) pBuffer[2 + j] = '7'; szGetMsg[63+j] = pBuffer[2+j]; } //memcpy((char*)&szGetMsg[2],(char*)&pBuffer[2],6); } else if (1 == type) { szGetMsg[1] = 49; szGetMsg[2] = alarmNum +48; for (int i=3; i< (alarmNum + 3); i++) { int ctrlNum = (unsigned char)pBuffer[i]; szGetMsg[ctrlNum+3] = '1'; } for(int j=0; j<6; j++) { szGetMsg[63+j] = pBuffer[alarmNum+3+j]; } } else if (2 == type) { szGetMsg[1] = 2; szGetMsg[2] = alarmNum +48; for (int i=3; i< (alarmNum + 3); i++) { int ctrlNum = (int)(unsigned char)pBuffer[i]; szGetMsg[ctrlNum+3] = 2 + 48; } for(int j=0; j<6; j++) { szGetMsg[alarmNum+3+j] = pBuffer[alarmNum+3+j]; } } memcpy(m_szJB1501A64P_1Msg, szGetMsg, sizeof(szGetMsg)); } WORD CJB1501A64P::RtnCheck(char Msg[VAR_MSG]) { int len ,index; len = 2; index = 7; char ch[2]; ch[0] = Msg[index]; ch[1] = Msg[index+1]; if (atoi(ch)==ERR_CID_RTN_VAR) { return ERR_CID_RTN_VAR; } else if (atoi(ch)==ERR_CID_RTN_CHKSUM) { return ERR_CID_RTN_CHKSUM; } else if (atoi(ch)==ERR_CID_RTN_LCHKSUM) { return ERR_CID_RTN_LCHKSUM; } else if (atoi(ch)==ERR_CID_RTN_CID2) { return ERR_CID_RTN_CID2; } else if (atoi(ch)==ERR_CID_RTN_FORMAT) { return ERR_CID_RTN_FORMAT; } else if (atoi(ch)==ERR_CID_RTN_INVALI_DATA) { return ERR_CID_RTN_INVALI_DATA; } else /*if (atoi(ch)==ERR_CID_RTN_NORMAL)*/ { return ERR_CID_RTN_NORMAL; } }