| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328 |
- #include "stdafx.h"
- #include "DataMate3000.h"
- #include "CommProcess.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- CDataMate3000::CDataMate3000(char *szPath,char *szIniName,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_szDataMate3000_42Msg[i], 0, sizeof(m_szDataMate3000_42Msg[i]));
- memset(m_szDataMate3000_43Msg[i], 0, sizeof(m_szDataMate3000_43Msg[i]));
- memset(m_szDataMate3000_47Msg[i], 0, sizeof(m_szDataMate3000_47Msg[i]));
- memset(m_szDataMate3000_4DMsg[i], 0, sizeof(m_szDataMate3000_4DMsg[i]));
- //memset(m_szDataMate3000_4FMsg, 0, sizeof(m_szDataMate3000_4FMsg));
- //memset(m_szDataMate3000_50Msg, 0, sizeof(m_szDataMate3000_50Msg));
- //memset(m_szDataMate3000_51Msg, 0, sizeof(m_szDataMate3000_51Msg));
- //memset(m_szDataMate3000_80Msg, 0, sizeof(m_szDataMate3000_80Msg));
- //memset(m_szDataMate3000_81Msg, 0, sizeof(m_szDataMate3000_81Msg));
- memset(m_szDataMate3000_82Msg[i], 0, sizeof(m_szDataMate3000_82Msg[i]));
- memset(m_szDataMate3000_45Msg[i], 0, sizeof(m_szDataMate3000_45Msg[i]));
- //memset(m_szDataMate3000_49Msg, 0, sizeof(m_szDataMate3000_49Msg));
- //memset(m_szDataMate3000_4EMsg, 0, sizeof(m_szDataMate3000_4EMsg));
- m_devOnline[i] = TRUE;
- m_dwOnlineTick[i] = 0;
- }
- }
- CDataMate3000::~CDataMate3000()
- {
- #if IS_USE_READMSG_CS
- DeleteCriticalSection( &m_csReadMsg );
- #endif
- MTVERIFY( CloseHandle( m_hSemComm ) );
- CloseComm();
- }
- BOOL CDataMate3000::DataMate3000OpenComm(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 CDataMate3000::SendReadRequest(
- char *szPath,
- char *szIniName,
- int nCommPort,
- int nAddr,
- char *szCmd,
- char *szMsg,
- int nReversed1,
- int nReversed2,
- int nReversed3,
- int nReversed4,
- int nReversed5,
- float fReversed1,
- float fReversed2,
- float fReversed3,
- char *szReversed1,
- char *szReversed2,
- char *szReversed3,
- char *szReversed4,
- char *szReversed5 )
- {
- int nIndex = 0, nLen = 0, StaBit = 0, EndBit = 0;
- char szSendMsg[DATAMATE3000_SEND_MSG];
- char szType[TYPE_LENGTH] = {0};
- char szCid2[CID2_LENGTH] = {0};
- char szAddr[2] = {0};
- RESPONSE_STRUCT szSend = {0};
- memset(&szSend, 0, sizeof(RESPONSE_STRUCT));
- memset(szSendMsg, 0, DATAMATE3000_SEND_MSG);
- memset(szMsg, 0, VAR_MSG);
- GetIniInfo(szPath, szIniName, szCmd, szCid2, szType, nIndex, nLen, StaBit, EndBit);
- szSend.Sol = 0x7E;
- szSend.Ver[0] = '2';
- szSend.Ver[1] = '1';
- //设备地址描述
- sprintf(szAddr, "%x", nAddr);
- szAddr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
- szAddr[1] = ByteToAscii(nAddr & 0x0f);
- memcpy(szSend.Adr, szAddr, 2);
- //Cid1
- szSend.Cid1[0] = '6';
- szSend.Cid1[1] = '0';
- //cid2
- memcpy(szSend.Cid2, szCid2, 2);
- //memset(szSend.Length, 0, 4);
- //length
- szSend.Length[0] = '0';
- szSend.Length[1] = '0';
- szSend.Length[2] = '0';
- szSend.Length[3] = '0';
- //chksum
- memset(szSend.Chksum, 0,sizeof(szSend.Chksum));
- memcpy(szSendMsg, &szSend, sizeof(RESPONSE_STRUCT));
- GetChkSum(szSendMsg, (char *)szSend.Chksum, sizeof(RESPONSE_STRUCT));
- //eol
- szSend.Eol = 0x0D;
-
- memcpy(szSendMsg, &szSend, sizeof(RESPONSE_STRUCT));
- CCommProcess *pComm = FindComm(nCommPort);
- if( pComm == NULL ) return -1;
- int nRet = -1;
- if( nAddr < 1 ) return -1;
- if(
- ( strlen(m_szDataMate3000_42Msg[nAddr-1]) == 0 &&
- ( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 ||
- strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 ) ) ||
- ( strlen(m_szDataMate3000_43Msg[nAddr-1]) == 0 &&
- strcmp(szCmd, "cmd-4") == 0 ) ||
- ( strlen(m_szDataMate3000_47Msg[nAddr-1]) == 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 ) ) ||
- ( strlen(m_szDataMate3000_4DMsg[nAddr-1]) == 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 ) )||
- ( strlen(m_szDataMate3000_82Msg[nAddr-1]) == 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-1") == 0 ||
- strcmp(szCmd, "cmd-4") == 0 ||
- strcmp(szCmd, "cmd-7") == 0 ||
- strcmp(szCmd, "cmd-11") == 0 ||
- strcmp(szCmd, "cmd-17") == 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 = GetDataMate3000_42VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetDataMate3000_43VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType);
-
- nRet = GetDataMate3000_47VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetDataMate3000_4DVarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetDataMate3000_82VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType, StaBit, EndBit);
-
- return nRet;
- }
- int CDataMate3000::GetDataMate3000_42VarMsg(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- //memcpy(szMsg, m_szDataMate3000_42Msg + nIndex, nLen);
- DataConversion(szType, m_szDataMate3000_42Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CDataMate3000::GetDataMate3000_43VarMsg(
- 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-4") == 0 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- //memcpy(szMsg, m_szDataMate3000_43Msg + nIndex, nLen);
- DataConversion(szType, m_szDataMate3000_43Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CDataMate3000::GetDataMate3000_47VarMsg(
- 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-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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- //memcpy(szMsg, m_szDataMate3000_47Msg + nIndex, nLen);
- DataConversion(szType, m_szDataMate3000_47Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CDataMate3000::GetDataMate3000_4DVarMsg(
- 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 ||
- strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- //memcpy(szMsg, m_szDataMate3000_4DMsg + nIndex, nLen);
- DataConversion(szType, m_szDataMate3000_4DMsg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CDataMate3000::GetDataMate3000_82VarMsg(
- int nAddr,
- char szCmd[MAX_CMD], // 命令
- char szMsg[VAR_MSG], // 接收Buffer
- int &nIndex, // 变量索引,针对接收Buffer而言
- int &nLen, // 变量长度
- char szType[TYPE_LENGTH], // 变量数据类型
- int StaBit,
- int EndBit
- )
- {
- int nRet = 0;
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- //memcpy(szMsg, m_szDataMate3000_82Msg + nIndex, nLen);
- DataConversion(szType, m_szDataMate3000_82Msg[nAddr - 1] + nIndex, szMsg, nLen, StaBit, EndBit);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CDataMate3000::GetDataMate3000_45VarMsg(
- 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-44") == 0)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(szMsg, m_szDataMate3000_45Msg[nAddr - 1] + nIndex, nLen);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CDataMate3000::GetDeviceParam(
- CCommProcess *pComm, //串口对象指针
- int nAddr,
- char szSendMsg[DATAMATE3000_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 CDataMate3000::SetDeviceParam(
- CCommProcess *pComm, //串口对象指针
- int nAddr,
- char szSendMsg[DATAMATE3000_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 CDataMate3000::SetDataMate3000_42VarMsg( 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szDataMate3000_42Msg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_42Msg[nAddr - 1]));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CDataMate3000::SetDataMate3000_43VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
- {
- if( strcmp(szCmd, "cmd-4") == 0)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szDataMate3000_43Msg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_43Msg[nAddr - 1]));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CDataMate3000::SetDataMate3000_47VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
- {
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szDataMate3000_47Msg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_47Msg[nAddr - 1]));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CDataMate3000::SetDataMate3000_4DVarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
- {
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szDataMate3000_4DMsg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_4DMsg[nAddr - 1]));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CDataMate3000::SetDataMate3000_82VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
- {
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szDataMate3000_82Msg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_82Msg[nAddr - 1]));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- WORD CDataMate3000::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 CDataMate3000::GetLCheckSum(char *pBuf, int len)
- {
- //WORD iSum = 0;
- char chCompliment = 0;
- //unsigned char chCompliment[2] = {0};
- for(int i=0; i<len; i++)//求和
- {
- chCompliment += AsciiToBYTE(pBuf[i]);
- //chCompliment += pBuf[i];
- }
- chCompliment = ~chCompliment;//取反
- chCompliment++;
- return chCompliment;
- }
- // 发送设置设备参数请求
- int CDataMate3000::SendSetReuest(
- 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), IniSendlen(0);
- char szSendMsg[DATAMATE3000_SEND_MSG] = {0},IniSendCMD[MAX_CMD] = {0}, szDataType[CMD_TYPE] = {0};
- char szAddr[2] = {0};
- char szLength[4] = {0};
- REQUEST_STRUCT szSend = {0};
- memset(szSendMsg, 0, DATAMATE3000_SEND_MSG);
- GetIniInfo(szPath, szIniName, szCmd, IniSendCMD, IniSendlen,nIndex, nLen, StaBit, EndBit,szDataType);
- //sol
- szSend.Sol = 0x7E;
- //ver
- szSend.Ver[0] = '2';
- szSend.Ver[1] = '1';
- //adr
- sprintf(szAddr, "%x", nAddr);
- szAddr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
- szAddr[1] = ByteToAscii(nAddr & 0x0f);
- memcpy(szSend.Adr, szAddr, 2);
- //cid1
- szSend.Cid1[0] = '6';
- szSend.Cid1[1] = '0';
- //cid2
- memcpy(szSend.Cid2, IniSendCMD, 2);
- memset(szSend.Length, 0, 4);
- //GetDataLength(2, szLength);//取数据长度
- //szSend.Length[0] = ByteToAscii(szLength[0]);
- //szSend.Length[1] = szLength[1];
- //szSend.Length[2] = szLength[2];
- //szSend.Length[3] = szLength[3];
- //length
- szSend.Length[1] = '0';
- szSend.Length[2] = '0';
- szSend.Length[3] = '2';
- szSend.Length[0] = 'E';
- //szInfo
- memcpy(szSend.szInfo,szMsg, sizeof(szSend.szInfo));
-
- memset(szSend.Chksum, 0,sizeof(szSend.Chksum));
- szSend.Eol = 0x0D;
- memcpy(szSendMsg, &szSend, sizeof(REQUEST_STRUCT));
- GetChkSum(szSendMsg, (char *)szSend.Chksum, sizeof(REQUEST_STRUCT));
- szSend.Eol = 0x0D;
- memcpy(szSendMsg, &szSend, sizeof(REQUEST_STRUCT));
- CCommProcess *pComm = FindComm(nCommPort);
- if( pComm == NULL ) return -1;
- int nRet = -1;
- if( nAddr < 1 ) return -1;
- if( strcmp(szCmd, "cmd-44") == 0 )
- {
- SetDeviceParam( pComm, nAddr, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
- }
- return 0;
- }
- //读取配置文件
- int CDataMate3000::GetIniInfo(char *szPath,char *szIniName,char *szCmd,char *IniSendCMD,int &IniSendlen,int &nIndex,int &nLen,int &nSBit,int &nEBit,char *szDataType)
- {
- char szFile[MAX_PATH + 1] = "";
- memset(szDataType, 0, TYPE_LENGTH);
- wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);//只读config下面的ini
- GetPrivateProfileString(szCmd, "SendCmd", "", szCid2, CID2_LENGTH, szFile);//读取配置文件中的一段字符串
- GetPrivateProfileString(szCmd, "Type", "", szType, TYPE_LENGTH, szFile);
- nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);//从配置文件中取值
- nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
- nSBit = GetPrivateProfileInt(szCmd, "StaBit", 0, szFile);//从配置文件中取值
- nEBit = GetPrivateProfileInt(szCmd, "EndBit", 0, szFile);
- return 0;
- }
- int CDataMate3000::RequestStatus(
- char szCmd[MAX_CMD], // 命令
- CCommProcess *pComm, //串口对象指针
- char chSendMsg[DATAMATE3000_SEND_MSG] //发送Buffer
- )
- {
- int nRet = -1;
- #if DEBUG_DataMate3000
- if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口
- {
- int nDataLen = (int)strlen(chSendMsg);
- ResetEvent( m_hSemComm );
- int nResult = pComm->Write((unsigned char *)chSendMsg, nDataLen);
- if( nResult == nDataLen )
- {
- nRet = 0;
- }
- else
- {
- SetEvent( m_hSemComm );
- return ERR_CODE_DATAMATE3000_COM_INVALIDRES;
- }
- }
- else
- {
- return ERR_CODE_DATAMATE3000_COM_BUSY;
- }
- #endif
- return nRet;
- }
- int CDataMate3000::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_DataMate3000
- int nReceiveLen = 0;
- int nProcessLen = 0;
- int nReadLen = 0;
- //RESPONSE_STRUCT structResponse;
- //memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
-
- nReceiveLen = DATEMATE3000_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_DATAMATE3000_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_DATAMATE3000_COM_CHKSUM_LOST;
- }
- if (!CheckLength(pBuffer))
- {
- // 数据长度校检错误
- //TRACE("数据长度校检错误!\r\n");
- //AfxMessageBox("数据长度校检错误!");
- SetEvent( m_hSemComm );
- if( pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- return ERR_CODE_DATAMATE3000_COM_VARLEN;
- }
- int nRet = RtnCheck(pBuffer);
- if(0 != nRet)
- {
- //AfxMessageBox("校验出错");
- // 设置串口等待事件为有信号
- SetEvent( m_hSemComm );
- if( pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- return nRet;
- }
- SetDataMate3000_42VarMsg(nAddr, szCmd, pBuffer);
- SetDataMate3000_43VarMsg(nAddr, szCmd, pBuffer);
- SetDataMate3000_47VarMsg(nAddr, szCmd, pBuffer);
- SetDataMate3000_4DVarMsg(nAddr, szCmd, pBuffer);
- SetDataMate3000_82VarMsg(nAddr, szCmd, pBuffer);
- m_dwOnlineTick[nAddr - 1] = GetTickCount();
- // 设置串口等待事件为有信号
- SetEvent( m_hSemComm );
- if( pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- #else
- SimulationCommData();
- #endif
- return 0;
- }
- int CDataMate3000::WriteRequestStatus(
- char szCmd[MAX_CMD], // 命令
- CCommProcess *pComm, //串口对象指针
- char chSendMsg[DATAMATE3000_SEND_MSG] //发送Buffer
- )
- {
- #if DEBUG_DataMate3000
- 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_DATAMATE3000_COM_WRITE_DATA;
- }
- #endif
- return 0;
- }
- int CDataMate3000::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_DataMate3000
- int nReceiveLen = 0;
- int nProcessLen = 0;
- int nReadLen = 0;
- //RESPONSE_STRUCT structResponse;
- //memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
-
- nReceiveLen = DATEMATE3000_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_DATAMATE3000_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_DATAMATE3000_COM_CHKSUM_LOST;
- }
- if (!CheckLength(pBuffer))
- {
- // 数据长度校检错误
- //TRACE("数据长度校检错误!\r\n");
- //AfxMessageBox("数据长度校检错误!");
- SetEvent( m_hSemComm );
- if( pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- return ERR_CODE_DATAMATE3000_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 CDataMate3000::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_szDataMate3000_42Msg[0] = 0x7E;
- m_szDataMate3000_42Msg[1] = 0x32;
- m_szDataMate3000_42Msg[2] = 0x31;
- m_szDataMate3000_42Msg[3] = 0x30;
- m_szDataMate3000_42Msg[4] = 0x31;
- m_szDataMate3000_42Msg[5] = 0x36;
- m_szDataMate3000_42Msg[6] = 0x30;
- m_szDataMate3000_42Msg[7] = 0x30;
- m_szDataMate3000_42Msg[8] = 0x30;
- m_szDataMate3000_42Msg[9] = 0x34;
- m_szDataMate3000_42Msg[10] = 0x30;
- m_szDataMate3000_42Msg[11] = 0x30;
- m_szDataMate3000_42Msg[12] = 0x43;
- m_szDataMate3000_42Msg[13] = 0x30;
- m_szDataMate3000_42Msg[14] = 0x30;
- m_szDataMate3000_42Msg[15] = 0x44;
- m_szDataMate3000_42Msg[16] = 0x45;
- m_szDataMate3000_42Msg[17] = 0x30;
- m_szDataMate3000_42Msg[18] = 0x32;
- m_szDataMate3000_42Msg[19] = 0x42;
- m_szDataMate3000_42Msg[20] = 0x43;
- m_szDataMate3000_42Msg[21] = 0x30;
- m_szDataMate3000_42Msg[22] = 0x30;
- m_szDataMate3000_42Msg[23] = 0x30;
- m_szDataMate3000_42Msg[24] = 0x30;
- m_szDataMate3000_42Msg[25] = 0x46;
- m_szDataMate3000_42Msg[26] = 0x42;
- m_szDataMate3000_42Msg[27] = 0x30;
- m_szDataMate3000_42Msg[28] = 0x46;
- m_szDataMate3000_42Msg[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_szDataMate3000_82Msg[0] = 0x7E;
- m_szDataMate3000_82Msg[1] = 0x32;
- m_szDataMate3000_82Msg[2] = 0x31;
- m_szDataMate3000_82Msg[3] = 0x30;
- m_szDataMate3000_82Msg[4] = 0x31;
- m_szDataMate3000_82Msg[5] = 0x36;
- m_szDataMate3000_82Msg[6] = 0x30;
- m_szDataMate3000_82Msg[7] = 0x30;
- m_szDataMate3000_82Msg[8] = 0x30;
- m_szDataMate3000_82Msg[9] = 0x34;
- m_szDataMate3000_82Msg[10] = 0x30;
- m_szDataMate3000_82Msg[11] = 0x30;
- m_szDataMate3000_82Msg[12] = 0x43;
- m_szDataMate3000_82Msg[13] = 0x30;
- m_szDataMate3000_82Msg[14] = 0x31;
- m_szDataMate3000_82Msg[15] = 0x32;
- m_szDataMate3000_82Msg[16] = 0x37;
- m_szDataMate3000_82Msg[17] = 0x30;
- m_szDataMate3000_82Msg[18] = 0x30;
- m_szDataMate3000_82Msg[19] = 0x30;
- m_szDataMate3000_82Msg[20] = 0x30;
- m_szDataMate3000_82Msg[21] = 0x30;
- m_szDataMate3000_82Msg[22] = 0x30;
- m_szDataMate3000_82Msg[23] = 0x30;
- m_szDataMate3000_82Msg[24] = 0x30;
- m_szDataMate3000_82Msg[25] = 0x46;
- m_szDataMate3000_82Msg[26] = 0x42;
- m_szDataMate3000_82Msg[27] = 0x35;
- m_szDataMate3000_82Msg[28] = 0x35;
- m_szDataMate3000_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_szDataMate3000_47Msg[0] = 0x7E;
- m_szDataMate3000_47Msg[1] = 0x32;
- m_szDataMate3000_47Msg[2] = 0x31;
- m_szDataMate3000_47Msg[3] = 0x30;
- m_szDataMate3000_47Msg[4] = 0x31;
- m_szDataMate3000_47Msg[5] = 0x36;
- m_szDataMate3000_47Msg[6] = 0x30;
- m_szDataMate3000_47Msg[7] = 0x30;
- m_szDataMate3000_47Msg[8] = 0x30;
- m_szDataMate3000_47Msg[9] = 0x35;
- m_szDataMate3000_47Msg[10] = 0x30;
- m_szDataMate3000_47Msg[11] = 0x31;
- m_szDataMate3000_47Msg[12] = 0x41;
- m_szDataMate3000_47Msg[13] = 0x30;
- m_szDataMate3000_47Msg[14] = 0x30;
- m_szDataMate3000_47Msg[15] = 0x30;
- m_szDataMate3000_47Msg[16] = 0x30;
- m_szDataMate3000_47Msg[17] = 0x30;
- m_szDataMate3000_47Msg[18] = 0x30;
- m_szDataMate3000_47Msg[19] = 0x30;
- m_szDataMate3000_47Msg[20] = 0x30;
- m_szDataMate3000_47Msg[21] = 0x30;
- m_szDataMate3000_47Msg[22] = 0x30;
- m_szDataMate3000_47Msg[23] = 0x46;
- m_szDataMate3000_47Msg[24] = 0x41;
- m_szDataMate3000_47Msg[25] = 0x30;
- m_szDataMate3000_47Msg[26] = 0x30;
- m_szDataMate3000_47Msg[27] = 0x31;
- m_szDataMate3000_47Msg[28] = 0x45;
- m_szDataMate3000_47Msg[29] = 0x30;
- m_szDataMate3000_47Msg[30] = 0x32;
- m_szDataMate3000_47Msg[31] = 0x35;
- m_szDataMate3000_47Msg[32] = 0x38;
- m_szDataMate3000_47Msg[33] = 0x30;
- m_szDataMate3000_47Msg[34] = 0x30;
- m_szDataMate3000_47Msg[35] = 0x36;
- m_szDataMate3000_47Msg[36] = 0x34;
- m_szDataMate3000_47Msg[37] = 0x30;
- m_szDataMate3000_47Msg[38] = 0x30;
- m_szDataMate3000_47Msg[39] = 0x46;
- m_szDataMate3000_47Msg[40] = 0x38;
- m_szDataMate3000_47Msg[41] = 0x36;
- m_szDataMate3000_47Msg[42] = 0x39;
- m_szDataMate3000_47Msg[43] = 0x0D;
- //m_szDataMate3000_41Msg[44] = 0x42;
- //m_szDataMate3000_41Msg[45] = 0x34;
- //m_szDataMate3000_41Msg[46] = 0x33;
- //m_szDataMate3000_41Msg[47] = 0x30;
- //m_szDataMate3000_41Msg[48] = 0x30;
- //m_szDataMate3000_41Msg[49] = 0x30;
- //m_szDataMate3000_41Msg[50] = 0x30;
- //m_szDataMate3000_41Msg[51] = 0x35;
- //m_szDataMate3000_41Msg[52] = 0x42;
- //m_szDataMate3000_41Msg[53] = 0x34;
- //m_szDataMate3000_41Msg[54] = 0x33;
- //m_szDataMate3000_41Msg[55] = 0x30;
- //m_szDataMate3000_41Msg[56] = 0x30;
- //m_szDataMate3000_41Msg[57] = 0x30;
- //m_szDataMate3000_41Msg[58] = 0x30;
- //m_szDataMate3000_41Msg[59] = 0x35;
- //m_szDataMate3000_41Msg[60] = 0x42;
- //m_szDataMate3000_41Msg[61] = 0x34;
- //m_szDataMate3000_41Msg[62] = 0x33;
- //m_szDataMate3000_41Msg[63] = 0x30;
- //m_szDataMate3000_41Msg[64] = 0x30;
- //m_szDataMate3000_41Msg[65] = 0x30;
- //m_szDataMate3000_41Msg[66] = 0x30;
- //m_szDataMate3000_41Msg[67] = 0x32;
- //m_szDataMate3000_41Msg[68] = 0x30;
- //m_szDataMate3000_41Msg[69] = 0x34;
- //m_szDataMate3000_41Msg[70] = 0x31;
- //m_szDataMate3000_41Msg[71] = 0x30;
- //m_szDataMate3000_41Msg[72] = 0x30;
- //m_szDataMate3000_41Msg[73] = 0x30;
- //m_szDataMate3000_41Msg[74] = 0x30;
- //m_szDataMate3000_41Msg[75] = 0x32;
- //m_szDataMate3000_41Msg[76] = 0x30;
- //m_szDataMate3000_41Msg[77] = 0x34;
- //m_szDataMate3000_41Msg[78] = 0x31;
- //m_szDataMate3000_41Msg[79] = 0x30;
- //m_szDataMate3000_41Msg[80] = 0x30;
- //m_szDataMate3000_41Msg[81] = 0x30;
- //m_szDataMate3000_41Msg[82] = 0x30;
- //m_szDataMate3000_41Msg[83] = 0x32;
- //m_szDataMate3000_41Msg[84] = 0x30;
- //m_szDataMate3000_41Msg[85] = 0x34;
- //m_szDataMate3000_41Msg[86] = 0x31;
- //m_szDataMate3000_41Msg[87] = 0x30;
- //m_szDataMate3000_41Msg[88] = 0x30;
- //m_szDataMate3000_41Msg[89] = 0x30;
- //m_szDataMate3000_41Msg[90] = 0x30;
- //m_szDataMate3000_41Msg[91] = 0x31;
- //m_szDataMate3000_41Msg[92] = 0x30;
- //m_szDataMate3000_41Msg[93] = 0x34;
- //m_szDataMate3000_41Msg[94] = 0x31;
- //m_szDataMate3000_41Msg[95] = 0x30;
- //m_szDataMate3000_41Msg[96] = 0x30;
- //m_szDataMate3000_41Msg[97] = 0x38;
- //m_szDataMate3000_41Msg[98] = 0x30;
- //m_szDataMate3000_41Msg[99] = 0x30;
- //m_szDataMate3000_41Msg[100] = 0x39;
- //m_szDataMate3000_41Msg[101] = 0x34;
- //m_szDataMate3000_41Msg[102] = 0x35;
- //m_szDataMate3000_41Msg[103] = 0x30;
- //m_szDataMate3000_41Msg[104] = 0x30;
- //m_szDataMate3000_41Msg[105] = 0x30;
- //m_szDataMate3000_41Msg[106] = 0x30;
- //m_szDataMate3000_41Msg[107] = 0x30;
- //m_szDataMate3000_41Msg[108] = 0x30;
- //m_szDataMate3000_41Msg[109] = 0x45;
- //m_szDataMate3000_41Msg[110] = 0x30;
- //m_szDataMate3000_41Msg[111] = 0x31;
- //m_szDataMate3000_41Msg[112] = 0x38;
- //m_szDataMate3000_41Msg[113] = 0x0D;
- //m_szDataMate3000_41Msg[114] = 0x39;
- //m_szDataMate3000_41Msg[115] = 0x2E;
- //m_szDataMate3000_41Msg[116] = 0x30;
- //m_szDataMate3000_41Msg[117] = 0x20;
- //m_szDataMate3000_41Msg[118] = 0x33;
- //m_szDataMate3000_41Msg[119] = 0x35;
- //m_szDataMate3000_41Msg[110] = 0x2E;
- //m_szDataMate3000_41Msg[121] = 0x35;
- //m_szDataMate3000_41Msg[122] = 0x20;
- //m_szDataMate3000_41Msg[123] = 0x4C;
- //m_szDataMate3000_41Msg[124] = 0x4D;
- //m_szDataMate3000_41Msg[125] = 0x0D;
- //m_szDataMate3000_41Msg[126] = 0x32;
- //m_szDataMate3000_41Msg[127] = 0x0D;
- #endif
- }
- //char *CDataMate3000::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 CDataMate3000::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 CDataMate3000::CheckLength(char Msg[VAR_MSG])
- //{
- // WORD len ,index , lenID;
- // len = 4;
- // index = 9;
- // char ch[4];
- //
- // for (int i=0;i<len;i++)
- // {
- // ch[i] = Msg[index+i];
- // }
- //
- // lenID = AsciiToBYTE(ch[1]) + AsciiToBYTE(ch[2]) + AsciiToBYTE(ch[3]);
- // lenID = lenID%16;
- // lenID = ~lenID + 1;
- //
- // if (AsciiToBYTE(ch[0]) == lenID)
- // {
- // return TRUE;
- // }
- // else
- // {
- // return FALSE;
- // }
- //}
- WORD CDataMate3000::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;
- }
-
- }
|