复件 DataMate3000.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  1. #include "stdafx.h"
  2. #include "DataMate3000.h"
  3. #include "CommProcess.h"
  4. #ifdef _DEBUG
  5. #undef THIS_FILE
  6. static char THIS_FILE[]=__FILE__;
  7. #define new DEBUG_NEW
  8. #endif
  9. CDataMate3000::CDataMate3000(char *szPath,char *szIniName,int nCommPort, int nAddr,int nRate, int nDataBit,int nStopBit, int nParity,int nInterval)
  10. {
  11. #if IS_USE_READMSG_CS
  12. InitializeCriticalSection( &m_csReadMsg ); //初始化一个临界资源对象
  13. #endif
  14. MTVERIFY( m_hSemComm = CreateEvent( NULL, TRUE, TRUE, 0 ) ); //CreateEvent()创建或打开一个命名的或无名的事件对象
  15. for( int i = 0; i < MAX_ADDR; i++ )
  16. {
  17. memset(m_szDataMate3000_42Msg[i], 0, sizeof(m_szDataMate3000_42Msg[i]));
  18. memset(m_szDataMate3000_43Msg[i], 0, sizeof(m_szDataMate3000_43Msg[i]));
  19. memset(m_szDataMate3000_47Msg[i], 0, sizeof(m_szDataMate3000_47Msg[i]));
  20. memset(m_szDataMate3000_4DMsg[i], 0, sizeof(m_szDataMate3000_4DMsg[i]));
  21. //memset(m_szDataMate3000_4FMsg, 0, sizeof(m_szDataMate3000_4FMsg));
  22. //memset(m_szDataMate3000_50Msg, 0, sizeof(m_szDataMate3000_50Msg));
  23. //memset(m_szDataMate3000_51Msg, 0, sizeof(m_szDataMate3000_51Msg));
  24. //memset(m_szDataMate3000_80Msg, 0, sizeof(m_szDataMate3000_80Msg));
  25. //memset(m_szDataMate3000_81Msg, 0, sizeof(m_szDataMate3000_81Msg));
  26. memset(m_szDataMate3000_82Msg[i], 0, sizeof(m_szDataMate3000_82Msg[i]));
  27. memset(m_szDataMate3000_45Msg[i], 0, sizeof(m_szDataMate3000_45Msg[i]));
  28. //memset(m_szDataMate3000_49Msg, 0, sizeof(m_szDataMate3000_49Msg));
  29. //memset(m_szDataMate3000_4EMsg, 0, sizeof(m_szDataMate3000_4EMsg));
  30. m_devOnline[i] = TRUE;
  31. m_dwOnlineTick[i] = 0;
  32. }
  33. }
  34. CDataMate3000::~CDataMate3000()
  35. {
  36. #if IS_USE_READMSG_CS
  37. DeleteCriticalSection( &m_csReadMsg );
  38. #endif
  39. MTVERIFY( CloseHandle( m_hSemComm ) );
  40. CloseComm();
  41. }
  42. BOOL CDataMate3000::DataMate3000OpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  43. {
  44. BOOL bResult = FALSE;
  45. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  46. return bResult;
  47. }
  48. // 发送读取设备参数请求
  49. int CDataMate3000::SendReadRequest(
  50. char *szPath,
  51. char *szIniName,
  52. int nCommPort,
  53. int nAddr,
  54. char *szCmd,
  55. char *szMsg,
  56. int nReversed1,
  57. int nReversed2,
  58. int nReversed3,
  59. int nReversed4,
  60. int nReversed5,
  61. float fReversed1,
  62. float fReversed2,
  63. float fReversed3,
  64. char *szReversed1,
  65. char *szReversed2,
  66. char *szReversed3,
  67. char *szReversed4,
  68. char *szReversed5 )
  69. {
  70. int nIndex = 0, nLen = 0, StaBit = 0, EndBit = 0;
  71. char szSendMsg[DATAMATE3000_SEND_MSG];
  72. char szType[TYPE_LENGTH] = {0};
  73. char szCid2[CID2_LENGTH] = {0};
  74. char szAddr[2] = {0};
  75. RESPONSE_STRUCT szSend = {0};
  76. memset(&szSend, 0, sizeof(RESPONSE_STRUCT));
  77. memset(szSendMsg, 0, DATAMATE3000_SEND_MSG);
  78. memset(szMsg, 0, VAR_MSG);
  79. GetIniInfo(szPath, szIniName, szCmd, szCid2, szType, nIndex, nLen, StaBit, EndBit);
  80. szSend.Sol = 0x7E;
  81. szSend.Ver[0] = '2';
  82. szSend.Ver[1] = '1';
  83. //设备地址描述
  84. sprintf(szAddr, "%x", nAddr);
  85. szAddr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
  86. szAddr[1] = ByteToAscii(nAddr & 0x0f);
  87. memcpy(szSend.Adr, szAddr, 2);
  88. //Cid1
  89. szSend.Cid1[0] = '6';
  90. szSend.Cid1[1] = '0';
  91. //cid2
  92. memcpy(szSend.Cid2, szCid2, 2);
  93. //memset(szSend.Length, 0, 4);
  94. //length
  95. szSend.Length[0] = '0';
  96. szSend.Length[1] = '0';
  97. szSend.Length[2] = '0';
  98. szSend.Length[3] = '0';
  99. //chksum
  100. memset(szSend.Chksum, 0,sizeof(szSend.Chksum));
  101. memcpy(szSendMsg, &szSend, sizeof(RESPONSE_STRUCT));
  102. GetChkSum(szSendMsg, (char *)szSend.Chksum, sizeof(RESPONSE_STRUCT));
  103. //eol
  104. szSend.Eol = 0x0D;
  105. memcpy(szSendMsg, &szSend, sizeof(RESPONSE_STRUCT));
  106. CCommProcess *pComm = FindComm(nCommPort);
  107. if( pComm == NULL ) return -1;
  108. int nRet = -1;
  109. if( nAddr < 1 ) return -1;
  110. if(
  111. ( strlen(m_szDataMate3000_42Msg[nAddr-1]) == 0 &&
  112. ( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 ||
  113. strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 ) ) ||
  114. ( strlen(m_szDataMate3000_43Msg[nAddr-1]) == 0 &&
  115. strcmp(szCmd, "cmd-4") == 0 ) ||
  116. ( strlen(m_szDataMate3000_47Msg[nAddr-1]) == 0 &&
  117. ( strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 ||
  118. strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 ||
  119. strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 ) ) ||
  120. ( strlen(m_szDataMate3000_4DMsg[nAddr-1]) == 0 &&
  121. ( strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 ||
  122. strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 ||
  123. strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0 ) )||
  124. ( strlen(m_szDataMate3000_82Msg[nAddr-1]) == 0 &&
  125. ( strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 ||
  126. strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 ||
  127. strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 ||
  128. strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 ||
  129. strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 ||
  130. strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 ||
  131. strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 ||
  132. strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 ||
  133. strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 ||
  134. strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 ||
  135. strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 ||
  136. strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ||
  137. strcmp(szCmd, "cmd-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 ) )||
  138. strcmp(szCmd, "cmd-1") == 0 ||
  139. strcmp(szCmd, "cmd-4") == 0 ||
  140. strcmp(szCmd, "cmd-7") == 0 ||
  141. strcmp(szCmd, "cmd-11") == 0 ||
  142. strcmp(szCmd, "cmd-17") == 0
  143. )
  144. {
  145. nRet = GetDeviceParam( pComm, nAddr, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
  146. if( nRet != 0 )
  147. {
  148. return nRet;
  149. }
  150. }
  151. if( GetTickCount() - m_dwOnlineTick[nAddr - 1] > 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 )
  152. {
  153. m_devOnline[nAddr - 1] = FALSE;
  154. }
  155. else if( GetTickCount() - m_dwOnlineTick[nAddr - 1] < 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 )
  156. {
  157. m_devOnline[nAddr - 1] = TRUE;
  158. }
  159. if( m_devOnline[nAddr - 1] == FALSE )
  160. {
  161. return -1;
  162. }
  163. nRet = GetDataMate3000_42VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType);
  164. nRet = GetDataMate3000_43VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType);
  165. nRet = GetDataMate3000_47VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType);
  166. nRet = GetDataMate3000_4DVarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType);
  167. nRet = GetDataMate3000_82VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType, StaBit, EndBit);
  168. return nRet;
  169. }
  170. int CDataMate3000::GetDataMate3000_42VarMsg(
  171. int nAddr,
  172. char szCmd[MAX_CMD], // 命令
  173. char szMsg[VAR_MSG], // 接收Buffer
  174. int &nIndex, // 变量索引,针对接收Buffer而言
  175. int &nLen, // 变量长度
  176. char szType[TYPE_LENGTH] // 变量数据类型
  177. )
  178. {
  179. int nRet = 0;
  180. if( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0
  181. )
  182. {
  183. #if IS_USE_READMSG_CS
  184. EnterCriticalSection( &m_csReadMsg );
  185. #endif
  186. //memcpy(szMsg, m_szDataMate3000_42Msg + nIndex, nLen);
  187. DataConversion(szType, m_szDataMate3000_42Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
  188. #if IS_USE_READMSG_CS
  189. LeaveCriticalSection(&m_csReadMsg);
  190. #endif
  191. nRet = 0;
  192. }
  193. return nRet;
  194. }
  195. int CDataMate3000::GetDataMate3000_43VarMsg(
  196. int nAddr,
  197. char szCmd[MAX_CMD], // 命令
  198. char szMsg[VAR_MSG], // 接收Buffer
  199. int &nIndex, // 变量索引,针对接收Buffer而言
  200. int &nLen, // 变量长度
  201. char szType[TYPE_LENGTH] // 变量数据类型
  202. )
  203. {
  204. int nRet = 0;
  205. if(strcmp(szCmd, "cmd-4") == 0 )
  206. {
  207. #if IS_USE_READMSG_CS
  208. EnterCriticalSection( &m_csReadMsg );
  209. #endif
  210. //memcpy(szMsg, m_szDataMate3000_43Msg + nIndex, nLen);
  211. DataConversion(szType, m_szDataMate3000_43Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
  212. #if IS_USE_READMSG_CS
  213. LeaveCriticalSection(&m_csReadMsg);
  214. #endif
  215. nRet = 0;
  216. }
  217. return nRet;
  218. }
  219. int CDataMate3000::GetDataMate3000_47VarMsg(
  220. int nAddr,
  221. char szCmd[MAX_CMD], // 命令
  222. char szMsg[VAR_MSG], // 接收Buffer
  223. int &nIndex, // 变量索引,针对接收Buffer而言
  224. int &nLen, // 变量长度
  225. char szType[TYPE_LENGTH] // 变量数据类型
  226. )
  227. {
  228. int nRet = 0;
  229. if(
  230. strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 ||
  231. strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0
  232. )
  233. {
  234. #if IS_USE_READMSG_CS
  235. EnterCriticalSection( &m_csReadMsg );
  236. #endif
  237. //memcpy(szMsg, m_szDataMate3000_47Msg + nIndex, nLen);
  238. DataConversion(szType, m_szDataMate3000_47Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
  239. #if IS_USE_READMSG_CS
  240. LeaveCriticalSection(&m_csReadMsg);
  241. #endif
  242. nRet = 0;
  243. }
  244. return nRet;
  245. }
  246. int CDataMate3000::GetDataMate3000_4DVarMsg(
  247. int nAddr,
  248. char szCmd[MAX_CMD], // 命令
  249. char szMsg[VAR_MSG], // 接收Buffer
  250. int &nIndex, // 变量索引,针对接收Buffer而言
  251. int &nLen, // 变量长度
  252. char szType[TYPE_LENGTH] // 变量数据类型
  253. )
  254. {
  255. int nRet = 0;
  256. if(
  257. strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 ||
  258. strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0
  259. )
  260. {
  261. #if IS_USE_READMSG_CS
  262. EnterCriticalSection( &m_csReadMsg );
  263. #endif
  264. //memcpy(szMsg, m_szDataMate3000_4DMsg + nIndex, nLen);
  265. DataConversion(szType, m_szDataMate3000_4DMsg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
  266. #if IS_USE_READMSG_CS
  267. LeaveCriticalSection(&m_csReadMsg);
  268. #endif
  269. nRet = 0;
  270. }
  271. return nRet;
  272. }
  273. int CDataMate3000::GetDataMate3000_82VarMsg(
  274. int nAddr,
  275. char szCmd[MAX_CMD], // 命令
  276. char szMsg[VAR_MSG], // 接收Buffer
  277. int &nIndex, // 变量索引,针对接收Buffer而言
  278. int &nLen, // 变量长度
  279. char szType[TYPE_LENGTH], // 变量数据类型
  280. int StaBit,
  281. int EndBit
  282. )
  283. {
  284. int nRet = 0;
  285. if(
  286. strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 ||
  287. strcmp(szCmd, "cmd-20") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 ||
  288. strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 ||
  289. strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 ||
  290. strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 ||
  291. strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 ||
  292. strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 ||
  293. strcmp(szCmd, "cmd-38") == 0 || strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ||
  294. strcmp(szCmd, "cmd-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0
  295. )
  296. {
  297. #if IS_USE_READMSG_CS
  298. EnterCriticalSection( &m_csReadMsg );
  299. #endif
  300. //memcpy(szMsg, m_szDataMate3000_82Msg + nIndex, nLen);
  301. DataConversion(szType, m_szDataMate3000_82Msg[nAddr - 1] + nIndex, szMsg, nLen, StaBit, EndBit);
  302. #if IS_USE_READMSG_CS
  303. LeaveCriticalSection(&m_csReadMsg);
  304. #endif
  305. nRet = 0;
  306. }
  307. return nRet;
  308. }
  309. int CDataMate3000::GetDataMate3000_45VarMsg(
  310. int nAddr,
  311. char szCmd[MAX_CMD], // 命令
  312. char szMsg[VAR_MSG], // 接收Buffer
  313. int &nIndex, // 变量索引,针对接收Buffer而言
  314. int &nLen, // 变量长度
  315. char szType[TYPE_LENGTH] // 变量数据类型
  316. )
  317. {
  318. int nRet = 0;
  319. if(
  320. strcmp(szCmd, "cmd-44") == 0)
  321. {
  322. #if IS_USE_READMSG_CS
  323. EnterCriticalSection( &m_csReadMsg );
  324. #endif
  325. memcpy(szMsg, m_szDataMate3000_45Msg[nAddr - 1] + nIndex, nLen);
  326. #if IS_USE_READMSG_CS
  327. LeaveCriticalSection(&m_csReadMsg);
  328. #endif
  329. nRet = 0;
  330. }
  331. return nRet;
  332. }
  333. int CDataMate3000::GetDeviceParam(
  334. CCommProcess *pComm, //串口对象指针
  335. int nAddr,
  336. char szSendMsg[DATAMATE3000_SEND_MSG], //发送Buffer
  337. char szCmd[MAX_CMD], // 命令
  338. char szMsg[VAR_MSG], // 接收Buffer
  339. int &nIndex, // 变量索引,针对接收Buffer而言
  340. int &nLen, // 变量长度
  341. char szType[TYPE_LENGTH]) // 变量数据类型
  342. {
  343. int nRet = -1;
  344. nRet = RequestStatus(szCmd, pComm, szSendMsg);
  345. if( nRet != 0 )
  346. {
  347. return nRet; // 串口忙
  348. }
  349. nRet = ResponseStatus(pComm, nAddr, szCmd, szMsg, nIndex, nLen, szType);
  350. return nRet;
  351. }
  352. int CDataMate3000::SetDeviceParam(
  353. CCommProcess *pComm, //串口对象指针
  354. int nAddr,
  355. char szSendMsg[DATAMATE3000_SEND_MSG], //发送Buffer
  356. char szCmd[MAX_CMD], // 命令
  357. char szMsg[VAR_MSG], // 接收Buffer
  358. int &nIndex, // 变量索引,针对接收Buffer而言
  359. int &nLen, // 变量长度
  360. char szType[TYPE_LENGTH]) // 变量数据类型
  361. {
  362. int nRet = -1;
  363. nRet = WriteRequestStatus(szCmd, pComm, szSendMsg);
  364. if( nRet != 0 )
  365. {
  366. return nRet; // 串口忙
  367. }
  368. nRet = WriteResponseStatus(pComm, nAddr, szCmd, szMsg, nIndex, nLen, szType);
  369. return nRet;
  370. }
  371. void CDataMate3000::SetDataMate3000_42VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
  372. {
  373. if( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ||
  374. strcmp(szCmd, "cmd-4") == 0
  375. )
  376. {
  377. #if IS_USE_READMSG_CS
  378. EnterCriticalSection( &m_csReadMsg );
  379. #endif
  380. memcpy(m_szDataMate3000_42Msg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_42Msg[nAddr - 1]));
  381. #if IS_USE_READMSG_CS
  382. LeaveCriticalSection(&m_csReadMsg);
  383. #endif
  384. }
  385. }
  386. void CDataMate3000::SetDataMate3000_43VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
  387. {
  388. if( strcmp(szCmd, "cmd-4") == 0)
  389. {
  390. #if IS_USE_READMSG_CS
  391. EnterCriticalSection( &m_csReadMsg );
  392. #endif
  393. memcpy(m_szDataMate3000_43Msg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_43Msg[nAddr - 1]));
  394. #if IS_USE_READMSG_CS
  395. LeaveCriticalSection(&m_csReadMsg);
  396. #endif
  397. }
  398. }
  399. void CDataMate3000::SetDataMate3000_47VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
  400. {
  401. if(
  402. strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 ||
  403. strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0
  404. )
  405. {
  406. #if IS_USE_READMSG_CS
  407. EnterCriticalSection( &m_csReadMsg );
  408. #endif
  409. memcpy(m_szDataMate3000_47Msg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_47Msg[nAddr - 1]));
  410. #if IS_USE_READMSG_CS
  411. LeaveCriticalSection(&m_csReadMsg);
  412. #endif
  413. }
  414. }
  415. void CDataMate3000::SetDataMate3000_4DVarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
  416. {
  417. if(
  418. strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 ||
  419. strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0
  420. )
  421. {
  422. #if IS_USE_READMSG_CS
  423. EnterCriticalSection( &m_csReadMsg );
  424. #endif
  425. memcpy(m_szDataMate3000_4DMsg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_4DMsg[nAddr - 1]));
  426. #if IS_USE_READMSG_CS
  427. LeaveCriticalSection(&m_csReadMsg);
  428. #endif
  429. }
  430. }
  431. void CDataMate3000::SetDataMate3000_82VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
  432. {
  433. if(
  434. strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 ||
  435. strcmp(szCmd, "cmd-20") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 ||
  436. strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 ||
  437. strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 ||
  438. strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 ||
  439. strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 ||
  440. strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 ||
  441. strcmp(szCmd, "cmd-38") == 0 || strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ||
  442. strcmp(szCmd, "cmd-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0
  443. )
  444. {
  445. #if IS_USE_READMSG_CS
  446. EnterCriticalSection( &m_csReadMsg );
  447. #endif
  448. memcpy(m_szDataMate3000_82Msg[nAddr - 1], pBuffer, sizeof(m_szDataMate3000_82Msg[nAddr - 1]));
  449. #if IS_USE_READMSG_CS
  450. LeaveCriticalSection(&m_csReadMsg);
  451. #endif
  452. }
  453. }
  454. WORD CDataMate3000::GetDataLength(const WORD wLENID, char chLength[4])
  455. {
  456. char szLenID[3] = {0};
  457. //int nLen = 10;
  458. DigitToBinary(wLENID, szLenID, sizeof(szLenID));
  459. char chCheckSum = GetLCheckSum(szLenID, sizeof(szLenID));
  460. chLength[0] = chCheckSum;
  461. chLength[1] = szLenID[0];
  462. chLength[2] = szLenID[1];
  463. chLength[3] = szLenID[2];
  464. return 0;
  465. }
  466. char CDataMate3000::GetLCheckSum(char *pBuf, int len)
  467. {
  468. //WORD iSum = 0;
  469. char chCompliment = 0;
  470. //unsigned char chCompliment[2] = {0};
  471. for(int i=0; i<len; i++)//求和
  472. {
  473. chCompliment += AsciiToBYTE(pBuf[i]);
  474. //chCompliment += pBuf[i];
  475. }
  476. chCompliment = ~chCompliment;//取反
  477. chCompliment++;
  478. return chCompliment;
  479. }
  480. // 发送设置设备参数请求
  481. int CDataMate3000::SendSetReuest(
  482. char szPath[MAX_PATH], // 程序所在路径
  483. char szIniName[MAX_PATH], // 配置文件名称
  484. int nCommPort, // 串行端口
  485. int nAddr, // 设备地址
  486. char szCmd[MAX_CMD], // 请求命令
  487. char szMsg[VAR_MSG], // 响应的值
  488. int nReversed1, // 预留整形参数1接口
  489. int nReversed2, // 预留整形参数2接口
  490. int nReversed3, // 预留整形参数3接口
  491. int nReversed4, // 预留整形参数4接口
  492. int nReversed5, // 预留整形参数5接口
  493. float fReversed1, // 预留float参数1接口
  494. float fReversed2, // 预留float参数2接口
  495. float fReversed3, // 预留float参数3接口
  496. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  497. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  498. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  499. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  500. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  501. )
  502. {
  503. int nIndex(0), nLen (0), StaBit(0), EndBit(0), IniSendlen(0);
  504. char szSendMsg[DATAMATE3000_SEND_MSG] = {0},IniSendCMD[MAX_CMD] = {0}, szDataType[CMD_TYPE] = {0};
  505. char szAddr[2] = {0};
  506. char szLength[4] = {0};
  507. REQUEST_STRUCT szSend = {0};
  508. memset(szSendMsg, 0, DATAMATE3000_SEND_MSG);
  509. GetIniInfo(szPath, szIniName, szCmd, IniSendCMD, IniSendlen,nIndex, nLen, StaBit, EndBit,szDataType);
  510. //sol
  511. szSend.Sol = 0x7E;
  512. //ver
  513. szSend.Ver[0] = '2';
  514. szSend.Ver[1] = '1';
  515. //adr
  516. sprintf(szAddr, "%x", nAddr);
  517. szAddr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
  518. szAddr[1] = ByteToAscii(nAddr & 0x0f);
  519. memcpy(szSend.Adr, szAddr, 2);
  520. //cid1
  521. szSend.Cid1[0] = '6';
  522. szSend.Cid1[1] = '0';
  523. //cid2
  524. memcpy(szSend.Cid2, IniSendCMD, 2);
  525. memset(szSend.Length, 0, 4);
  526. //GetDataLength(2, szLength);//取数据长度
  527. //szSend.Length[0] = ByteToAscii(szLength[0]);
  528. //szSend.Length[1] = szLength[1];
  529. //szSend.Length[2] = szLength[2];
  530. //szSend.Length[3] = szLength[3];
  531. //length
  532. szSend.Length[1] = '0';
  533. szSend.Length[2] = '0';
  534. szSend.Length[3] = '2';
  535. szSend.Length[0] = 'E';
  536. //szInfo
  537. memcpy(szSend.szInfo,szMsg, sizeof(szSend.szInfo));
  538. memset(szSend.Chksum, 0,sizeof(szSend.Chksum));
  539. szSend.Eol = 0x0D;
  540. memcpy(szSendMsg, &szSend, sizeof(REQUEST_STRUCT));
  541. GetChkSum(szSendMsg, (char *)szSend.Chksum, sizeof(REQUEST_STRUCT));
  542. szSend.Eol = 0x0D;
  543. memcpy(szSendMsg, &szSend, sizeof(REQUEST_STRUCT));
  544. CCommProcess *pComm = FindComm(nCommPort);
  545. if( pComm == NULL ) return -1;
  546. int nRet = -1;
  547. if( nAddr < 1 ) return -1;
  548. if( strcmp(szCmd, "cmd-44") == 0 )
  549. {
  550. SetDeviceParam( pComm, nAddr, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
  551. }
  552. return 0;
  553. }
  554. //读取配置文件
  555. int CDataMate3000::GetIniInfo(char *szPath,char *szIniName,char *szCmd,char *IniSendCMD,int &IniSendlen,int &nIndex,int &nLen,int &nSBit,int &nEBit,char *szDataType)
  556. {
  557. char szFile[MAX_PATH + 1] = "";
  558. memset(szDataType, 0, TYPE_LENGTH);
  559. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);//只读config下面的ini
  560. GetPrivateProfileString(szCmd, "SendCmd", "", szCid2, CID2_LENGTH, szFile);//读取配置文件中的一段字符串
  561. GetPrivateProfileString(szCmd, "Type", "", szType, TYPE_LENGTH, szFile);
  562. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);//从配置文件中取值
  563. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  564. nSBit = GetPrivateProfileInt(szCmd, "StaBit", 0, szFile);//从配置文件中取值
  565. nEBit = GetPrivateProfileInt(szCmd, "EndBit", 0, szFile);
  566. return 0;
  567. }
  568. int CDataMate3000::RequestStatus(
  569. char szCmd[MAX_CMD], // 命令
  570. CCommProcess *pComm, //串口对象指针
  571. char chSendMsg[DATAMATE3000_SEND_MSG] //发送Buffer
  572. )
  573. {
  574. int nRet = -1;
  575. #if DEBUG_DataMate3000
  576. if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口
  577. {
  578. int nDataLen = (int)strlen(chSendMsg);
  579. ResetEvent( m_hSemComm );
  580. int nResult = pComm->Write((unsigned char *)chSendMsg, nDataLen);
  581. if( nResult == nDataLen )
  582. {
  583. nRet = 0;
  584. }
  585. else
  586. {
  587. SetEvent( m_hSemComm );
  588. return ERR_CODE_DATAMATE3000_COM_INVALIDRES;
  589. }
  590. }
  591. else
  592. {
  593. return ERR_CODE_DATAMATE3000_COM_BUSY;
  594. }
  595. #endif
  596. return nRet;
  597. }
  598. int CDataMate3000::ResponseStatus(
  599. CCommProcess *pComm, //串口对象指针
  600. int nAddr, // 设备地址
  601. char szCmd[MAX_CMD], // 命令
  602. char szMsg[VAR_MSG], // 接收Buffer
  603. int &nIndex, // 变量索引,针对接收Buffer而言
  604. int &nLen, // 变量长度
  605. char szType[TYPE_LENGTH] // 变量数据类型
  606. )
  607. {
  608. #if DEBUG_DataMate3000
  609. int nReceiveLen = 0;
  610. int nProcessLen = 0;
  611. int nReadLen = 0;
  612. //RESPONSE_STRUCT structResponse;
  613. //memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
  614. nReceiveLen = DATEMATE3000_RECEIVE_MSG;
  615. char *pBuffer = new char[ nReceiveLen ];
  616. memset(pBuffer, 0, nReceiveLen);
  617. nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen);
  618. if( nReadLen <= 0)
  619. {
  620. // 串口没有读到数据
  621. //TRACE("串口没有读到数据!\r\n");
  622. //AfxMessageBox("串口没有读到数据!");
  623. SetEvent( m_hSemComm );
  624. if( pBuffer != NULL)
  625. {
  626. delete[] pBuffer;
  627. pBuffer = NULL;
  628. }
  629. return ERR_CODE_DATAMATE3000_COM_READ_NO_DATA;
  630. }
  631. //int nTempLen = strlen(pBuffer);
  632. //CString str;
  633. //str.Format("%d", nTempLen);
  634. //AfxMessageBox(str);
  635. if (!ChkSumCheck(pBuffer, (int)strlen(pBuffer)))
  636. {
  637. // 校检错误
  638. //AfxMessageBox("校检错误");
  639. //TRACE("校检错误!\r\n");
  640. SetEvent( m_hSemComm );
  641. if( pBuffer != NULL)
  642. {
  643. delete[] pBuffer;
  644. pBuffer = NULL;
  645. }
  646. return ERR_CODE_DATAMATE3000_COM_CHKSUM_LOST;
  647. }
  648. if (!CheckLength(pBuffer))
  649. {
  650. // 数据长度校检错误
  651. //TRACE("数据长度校检错误!\r\n");
  652. //AfxMessageBox("数据长度校检错误!");
  653. SetEvent( m_hSemComm );
  654. if( pBuffer != NULL)
  655. {
  656. delete[] pBuffer;
  657. pBuffer = NULL;
  658. }
  659. return ERR_CODE_DATAMATE3000_COM_VARLEN;
  660. }
  661. int nRet = RtnCheck(pBuffer);
  662. if(0 != nRet)
  663. {
  664. //AfxMessageBox("校验出错");
  665. // 设置串口等待事件为有信号
  666. SetEvent( m_hSemComm );
  667. if( pBuffer != NULL)
  668. {
  669. delete[] pBuffer;
  670. pBuffer = NULL;
  671. }
  672. return nRet;
  673. }
  674. SetDataMate3000_42VarMsg(nAddr, szCmd, pBuffer);
  675. SetDataMate3000_43VarMsg(nAddr, szCmd, pBuffer);
  676. SetDataMate3000_47VarMsg(nAddr, szCmd, pBuffer);
  677. SetDataMate3000_4DVarMsg(nAddr, szCmd, pBuffer);
  678. SetDataMate3000_82VarMsg(nAddr, szCmd, pBuffer);
  679. m_dwOnlineTick[nAddr - 1] = GetTickCount();
  680. // 设置串口等待事件为有信号
  681. SetEvent( m_hSemComm );
  682. if( pBuffer != NULL)
  683. {
  684. delete[] pBuffer;
  685. pBuffer = NULL;
  686. }
  687. #else
  688. SimulationCommData();
  689. #endif
  690. return 0;
  691. }
  692. int CDataMate3000::WriteRequestStatus(
  693. char szCmd[MAX_CMD], // 命令
  694. CCommProcess *pComm, //串口对象指针
  695. char chSendMsg[DATAMATE3000_SEND_MSG] //发送Buffer
  696. )
  697. {
  698. #if DEBUG_DataMate3000
  699. int nDataLen = (int)strlen(chSendMsg);
  700. ResetEvent( m_hSemComm );
  701. int nResult = pComm->Write((unsigned char *)chSendMsg, nDataLen);
  702. if( nResult == nDataLen )
  703. {
  704. }
  705. else
  706. {
  707. SetEvent( m_hSemComm );
  708. return EER_CODE_DATAMATE3000_COM_WRITE_DATA;
  709. }
  710. #endif
  711. return 0;
  712. }
  713. int CDataMate3000::WriteResponseStatus(
  714. CCommProcess *pComm, //串口对象指针
  715. int nAddr, // 设备地址
  716. char szCmd[MAX_CMD], // 命令
  717. char szMsg[VAR_MSG], // 接收Buffer
  718. int &nIndex, // 变量索引,针对接收Buffer而言
  719. int &nLen, // 变量长度
  720. char szType[TYPE_LENGTH] // 变量数据类型
  721. )
  722. {
  723. #if DEBUG_DataMate3000
  724. int nReceiveLen = 0;
  725. int nProcessLen = 0;
  726. int nReadLen = 0;
  727. //RESPONSE_STRUCT structResponse;
  728. //memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
  729. nReceiveLen = DATEMATE3000_RECEIVE_MSG;
  730. char *pBuffer = new char[ nReceiveLen ];
  731. memset(pBuffer, 0, nReceiveLen);
  732. nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen);
  733. if( nReadLen <= 0)
  734. {
  735. // 串口没有读到数据
  736. //TRACE("串口没有读到数据!\r\n");
  737. //AfxMessageBox("串口没有读到数据!");
  738. SetEvent( m_hSemComm );
  739. if( pBuffer != NULL)
  740. {
  741. delete[] pBuffer;
  742. pBuffer = NULL;
  743. }
  744. return ERR_CODE_DATAMATE3000_COM_READ_NO_DATA;
  745. }
  746. #if 0
  747. //int nTempLen = strlen(pBuffer);
  748. //CString str;
  749. //str.Format("%d", nTempLen);
  750. //AfxMessageBox(str);
  751. if (!ChkSumCheck(pBuffer, strlen(pBuffer)))
  752. {
  753. // 校检错误
  754. //AfxMessageBox("校检错误");
  755. //TRACE("校检错误!\r\n");
  756. SetEvent( m_hSemComm );
  757. if( pBuffer != NULL)
  758. {
  759. delete[] pBuffer;
  760. pBuffer = NULL;
  761. }
  762. return ERR_CODE_DATAMATE3000_COM_CHKSUM_LOST;
  763. }
  764. if (!CheckLength(pBuffer))
  765. {
  766. // 数据长度校检错误
  767. //TRACE("数据长度校检错误!\r\n");
  768. //AfxMessageBox("数据长度校检错误!");
  769. SetEvent( m_hSemComm );
  770. if( pBuffer != NULL)
  771. {
  772. delete[] pBuffer;
  773. pBuffer = NULL;
  774. }
  775. return ERR_CODE_DATAMATE3000_COM_VARLEN;
  776. }
  777. int nRet = RtnCheck(pBuffer);
  778. if(0 != nRet)
  779. {
  780. //AfxMessageBox("校验出错");
  781. // 设置串口等待事件为有信号
  782. SetEvent( m_hSemComm );
  783. if( pBuffer != NULL)
  784. {
  785. delete[] pBuffer;
  786. pBuffer = NULL;
  787. }
  788. return nRet;
  789. }
  790. #endif
  791. // 设置串口等待事件为有信号
  792. SetEvent( m_hSemComm );
  793. if( pBuffer != NULL)
  794. {
  795. delete[] pBuffer;
  796. pBuffer = NULL;
  797. }
  798. #else
  799. SimulationCommData();
  800. #endif
  801. return 0;
  802. }
  803. void CDataMate3000::SimulationCommData(void)
  804. {
  805. /*cid2 =42 :7E 32 31 30 31 36 30 30 30 34 30 30 43
  806. 30 30 44 45 30 32 42 43 30 30 30 30 46 42 30 46 0D */
  807. #if 0
  808. m_szDataMate3000_42Msg[0] = 0x7E;
  809. m_szDataMate3000_42Msg[1] = 0x32;
  810. m_szDataMate3000_42Msg[2] = 0x31;
  811. m_szDataMate3000_42Msg[3] = 0x30;
  812. m_szDataMate3000_42Msg[4] = 0x31;
  813. m_szDataMate3000_42Msg[5] = 0x36;
  814. m_szDataMate3000_42Msg[6] = 0x30;
  815. m_szDataMate3000_42Msg[7] = 0x30;
  816. m_szDataMate3000_42Msg[8] = 0x30;
  817. m_szDataMate3000_42Msg[9] = 0x34;
  818. m_szDataMate3000_42Msg[10] = 0x30;
  819. m_szDataMate3000_42Msg[11] = 0x30;
  820. m_szDataMate3000_42Msg[12] = 0x43;
  821. m_szDataMate3000_42Msg[13] = 0x30;
  822. m_szDataMate3000_42Msg[14] = 0x30;
  823. m_szDataMate3000_42Msg[15] = 0x44;
  824. m_szDataMate3000_42Msg[16] = 0x45;
  825. m_szDataMate3000_42Msg[17] = 0x30;
  826. m_szDataMate3000_42Msg[18] = 0x32;
  827. m_szDataMate3000_42Msg[19] = 0x42;
  828. m_szDataMate3000_42Msg[20] = 0x43;
  829. m_szDataMate3000_42Msg[21] = 0x30;
  830. m_szDataMate3000_42Msg[22] = 0x30;
  831. m_szDataMate3000_42Msg[23] = 0x30;
  832. m_szDataMate3000_42Msg[24] = 0x30;
  833. m_szDataMate3000_42Msg[25] = 0x46;
  834. m_szDataMate3000_42Msg[26] = 0x42;
  835. m_szDataMate3000_42Msg[27] = 0x30;
  836. m_szDataMate3000_42Msg[28] = 0x46;
  837. m_szDataMate3000_42Msg[29] = 0x0D;
  838. /*cid2 = 82:7E 32 31 30 31 36 30 30 30 34 30 30 43
  839. 30 31 32 37 30 30 30 30 30 30 30 30 46 42 35 35 0D */
  840. m_szDataMate3000_82Msg[0] = 0x7E;
  841. m_szDataMate3000_82Msg[1] = 0x32;
  842. m_szDataMate3000_82Msg[2] = 0x31;
  843. m_szDataMate3000_82Msg[3] = 0x30;
  844. m_szDataMate3000_82Msg[4] = 0x31;
  845. m_szDataMate3000_82Msg[5] = 0x36;
  846. m_szDataMate3000_82Msg[6] = 0x30;
  847. m_szDataMate3000_82Msg[7] = 0x30;
  848. m_szDataMate3000_82Msg[8] = 0x30;
  849. m_szDataMate3000_82Msg[9] = 0x34;
  850. m_szDataMate3000_82Msg[10] = 0x30;
  851. m_szDataMate3000_82Msg[11] = 0x30;
  852. m_szDataMate3000_82Msg[12] = 0x43;
  853. m_szDataMate3000_82Msg[13] = 0x30;
  854. m_szDataMate3000_82Msg[14] = 0x31;
  855. m_szDataMate3000_82Msg[15] = 0x32;
  856. m_szDataMate3000_82Msg[16] = 0x37;
  857. m_szDataMate3000_82Msg[17] = 0x30;
  858. m_szDataMate3000_82Msg[18] = 0x30;
  859. m_szDataMate3000_82Msg[19] = 0x30;
  860. m_szDataMate3000_82Msg[20] = 0x30;
  861. m_szDataMate3000_82Msg[21] = 0x30;
  862. m_szDataMate3000_82Msg[22] = 0x30;
  863. m_szDataMate3000_82Msg[23] = 0x30;
  864. m_szDataMate3000_82Msg[24] = 0x30;
  865. m_szDataMate3000_82Msg[25] = 0x46;
  866. m_szDataMate3000_82Msg[26] = 0x42;
  867. m_szDataMate3000_82Msg[27] = 0x35;
  868. m_szDataMate3000_82Msg[28] = 0x35;
  869. m_szDataMate3000_82Msg[29] = 0x0D;
  870. /*cid2 = 47:7E 32 31 30 31 36 30 30 30 35 30 31 41
  871. 30 30 30 30 30 30 30 30 30 30 46 41 30 30 31 45 30
  872. 32 35 38 30 30 36 34 30 30 46 38 36 39 0D*/
  873. m_szDataMate3000_47Msg[0] = 0x7E;
  874. m_szDataMate3000_47Msg[1] = 0x32;
  875. m_szDataMate3000_47Msg[2] = 0x31;
  876. m_szDataMate3000_47Msg[3] = 0x30;
  877. m_szDataMate3000_47Msg[4] = 0x31;
  878. m_szDataMate3000_47Msg[5] = 0x36;
  879. m_szDataMate3000_47Msg[6] = 0x30;
  880. m_szDataMate3000_47Msg[7] = 0x30;
  881. m_szDataMate3000_47Msg[8] = 0x30;
  882. m_szDataMate3000_47Msg[9] = 0x35;
  883. m_szDataMate3000_47Msg[10] = 0x30;
  884. m_szDataMate3000_47Msg[11] = 0x31;
  885. m_szDataMate3000_47Msg[12] = 0x41;
  886. m_szDataMate3000_47Msg[13] = 0x30;
  887. m_szDataMate3000_47Msg[14] = 0x30;
  888. m_szDataMate3000_47Msg[15] = 0x30;
  889. m_szDataMate3000_47Msg[16] = 0x30;
  890. m_szDataMate3000_47Msg[17] = 0x30;
  891. m_szDataMate3000_47Msg[18] = 0x30;
  892. m_szDataMate3000_47Msg[19] = 0x30;
  893. m_szDataMate3000_47Msg[20] = 0x30;
  894. m_szDataMate3000_47Msg[21] = 0x30;
  895. m_szDataMate3000_47Msg[22] = 0x30;
  896. m_szDataMate3000_47Msg[23] = 0x46;
  897. m_szDataMate3000_47Msg[24] = 0x41;
  898. m_szDataMate3000_47Msg[25] = 0x30;
  899. m_szDataMate3000_47Msg[26] = 0x30;
  900. m_szDataMate3000_47Msg[27] = 0x31;
  901. m_szDataMate3000_47Msg[28] = 0x45;
  902. m_szDataMate3000_47Msg[29] = 0x30;
  903. m_szDataMate3000_47Msg[30] = 0x32;
  904. m_szDataMate3000_47Msg[31] = 0x35;
  905. m_szDataMate3000_47Msg[32] = 0x38;
  906. m_szDataMate3000_47Msg[33] = 0x30;
  907. m_szDataMate3000_47Msg[34] = 0x30;
  908. m_szDataMate3000_47Msg[35] = 0x36;
  909. m_szDataMate3000_47Msg[36] = 0x34;
  910. m_szDataMate3000_47Msg[37] = 0x30;
  911. m_szDataMate3000_47Msg[38] = 0x30;
  912. m_szDataMate3000_47Msg[39] = 0x46;
  913. m_szDataMate3000_47Msg[40] = 0x38;
  914. m_szDataMate3000_47Msg[41] = 0x36;
  915. m_szDataMate3000_47Msg[42] = 0x39;
  916. m_szDataMate3000_47Msg[43] = 0x0D;
  917. //m_szDataMate3000_41Msg[44] = 0x42;
  918. //m_szDataMate3000_41Msg[45] = 0x34;
  919. //m_szDataMate3000_41Msg[46] = 0x33;
  920. //m_szDataMate3000_41Msg[47] = 0x30;
  921. //m_szDataMate3000_41Msg[48] = 0x30;
  922. //m_szDataMate3000_41Msg[49] = 0x30;
  923. //m_szDataMate3000_41Msg[50] = 0x30;
  924. //m_szDataMate3000_41Msg[51] = 0x35;
  925. //m_szDataMate3000_41Msg[52] = 0x42;
  926. //m_szDataMate3000_41Msg[53] = 0x34;
  927. //m_szDataMate3000_41Msg[54] = 0x33;
  928. //m_szDataMate3000_41Msg[55] = 0x30;
  929. //m_szDataMate3000_41Msg[56] = 0x30;
  930. //m_szDataMate3000_41Msg[57] = 0x30;
  931. //m_szDataMate3000_41Msg[58] = 0x30;
  932. //m_szDataMate3000_41Msg[59] = 0x35;
  933. //m_szDataMate3000_41Msg[60] = 0x42;
  934. //m_szDataMate3000_41Msg[61] = 0x34;
  935. //m_szDataMate3000_41Msg[62] = 0x33;
  936. //m_szDataMate3000_41Msg[63] = 0x30;
  937. //m_szDataMate3000_41Msg[64] = 0x30;
  938. //m_szDataMate3000_41Msg[65] = 0x30;
  939. //m_szDataMate3000_41Msg[66] = 0x30;
  940. //m_szDataMate3000_41Msg[67] = 0x32;
  941. //m_szDataMate3000_41Msg[68] = 0x30;
  942. //m_szDataMate3000_41Msg[69] = 0x34;
  943. //m_szDataMate3000_41Msg[70] = 0x31;
  944. //m_szDataMate3000_41Msg[71] = 0x30;
  945. //m_szDataMate3000_41Msg[72] = 0x30;
  946. //m_szDataMate3000_41Msg[73] = 0x30;
  947. //m_szDataMate3000_41Msg[74] = 0x30;
  948. //m_szDataMate3000_41Msg[75] = 0x32;
  949. //m_szDataMate3000_41Msg[76] = 0x30;
  950. //m_szDataMate3000_41Msg[77] = 0x34;
  951. //m_szDataMate3000_41Msg[78] = 0x31;
  952. //m_szDataMate3000_41Msg[79] = 0x30;
  953. //m_szDataMate3000_41Msg[80] = 0x30;
  954. //m_szDataMate3000_41Msg[81] = 0x30;
  955. //m_szDataMate3000_41Msg[82] = 0x30;
  956. //m_szDataMate3000_41Msg[83] = 0x32;
  957. //m_szDataMate3000_41Msg[84] = 0x30;
  958. //m_szDataMate3000_41Msg[85] = 0x34;
  959. //m_szDataMate3000_41Msg[86] = 0x31;
  960. //m_szDataMate3000_41Msg[87] = 0x30;
  961. //m_szDataMate3000_41Msg[88] = 0x30;
  962. //m_szDataMate3000_41Msg[89] = 0x30;
  963. //m_szDataMate3000_41Msg[90] = 0x30;
  964. //m_szDataMate3000_41Msg[91] = 0x31;
  965. //m_szDataMate3000_41Msg[92] = 0x30;
  966. //m_szDataMate3000_41Msg[93] = 0x34;
  967. //m_szDataMate3000_41Msg[94] = 0x31;
  968. //m_szDataMate3000_41Msg[95] = 0x30;
  969. //m_szDataMate3000_41Msg[96] = 0x30;
  970. //m_szDataMate3000_41Msg[97] = 0x38;
  971. //m_szDataMate3000_41Msg[98] = 0x30;
  972. //m_szDataMate3000_41Msg[99] = 0x30;
  973. //m_szDataMate3000_41Msg[100] = 0x39;
  974. //m_szDataMate3000_41Msg[101] = 0x34;
  975. //m_szDataMate3000_41Msg[102] = 0x35;
  976. //m_szDataMate3000_41Msg[103] = 0x30;
  977. //m_szDataMate3000_41Msg[104] = 0x30;
  978. //m_szDataMate3000_41Msg[105] = 0x30;
  979. //m_szDataMate3000_41Msg[106] = 0x30;
  980. //m_szDataMate3000_41Msg[107] = 0x30;
  981. //m_szDataMate3000_41Msg[108] = 0x30;
  982. //m_szDataMate3000_41Msg[109] = 0x45;
  983. //m_szDataMate3000_41Msg[110] = 0x30;
  984. //m_szDataMate3000_41Msg[111] = 0x31;
  985. //m_szDataMate3000_41Msg[112] = 0x38;
  986. //m_szDataMate3000_41Msg[113] = 0x0D;
  987. //m_szDataMate3000_41Msg[114] = 0x39;
  988. //m_szDataMate3000_41Msg[115] = 0x2E;
  989. //m_szDataMate3000_41Msg[116] = 0x30;
  990. //m_szDataMate3000_41Msg[117] = 0x20;
  991. //m_szDataMate3000_41Msg[118] = 0x33;
  992. //m_szDataMate3000_41Msg[119] = 0x35;
  993. //m_szDataMate3000_41Msg[110] = 0x2E;
  994. //m_szDataMate3000_41Msg[121] = 0x35;
  995. //m_szDataMate3000_41Msg[122] = 0x20;
  996. //m_szDataMate3000_41Msg[123] = 0x4C;
  997. //m_szDataMate3000_41Msg[124] = 0x4D;
  998. //m_szDataMate3000_41Msg[125] = 0x0D;
  999. //m_szDataMate3000_41Msg[126] = 0x32;
  1000. //m_szDataMate3000_41Msg[127] = 0x0D;
  1001. #endif
  1002. }
  1003. //char *CDataMate3000::GetChkSum(char Msg[VAR_MSG])
  1004. //{
  1005. // WORD iMsg;
  1006. // char iChk[4];
  1007. // int len;
  1008. //
  1009. // len = sizeof(Msg); //取出数据长度 lenID/2
  1010. //
  1011. // iMsg = 0;
  1012. // for (int i=1;i<=(len-6);i++)
  1013. // {
  1014. // iMsg += Msg[i]; //ASSIC码值相加
  1015. // }
  1016. // iMsg = iMsg%65536;
  1017. // iMsg = ~iMsg + 1;
  1018. //
  1019. // itoa(iMsg,iChk,16);
  1020. //
  1021. // return iChk;
  1022. //}
  1023. //
  1024. //BOOL CDataMate3000::ChkSumCheck(char Msg[VAR_MSG])
  1025. //{
  1026. // WORD iMsg;
  1027. // char iChk[4];
  1028. // int len;
  1029. //
  1030. // len = sizeof(Msg); //取出数据长度 lenID/2
  1031. //
  1032. // iMsg = 0;
  1033. // for (int i=1;i<=(len-6);i++)
  1034. // {
  1035. // iMsg += Msg[i]; //ASSIC码值相加
  1036. // }
  1037. // iMsg = iMsg%65536;
  1038. // iMsg = ~iMsg + 1;
  1039. //
  1040. // itoa(iMsg,iChk,16);
  1041. //
  1042. // if ((lowercase2uppercase(iChk[0])==Msg[len-5]) && (lowercase2uppercase(iChk[1]) == Msg[len-4])
  1043. // && (lowercase2uppercase(iChk[2]) == Msg[len-3]) && (lowercase2uppercase(iChk[3]) == Msg[len-2]))
  1044. // {
  1045. // return TRUE;
  1046. // }
  1047. // else
  1048. // {
  1049. // return FALSE;
  1050. // }
  1051. //}
  1052. //
  1053. //BOOL CDataMate3000::CheckLength(char Msg[VAR_MSG])
  1054. //{
  1055. // WORD len ,index , lenID;
  1056. // len = 4;
  1057. // index = 9;
  1058. // char ch[4];
  1059. //
  1060. // for (int i=0;i<len;i++)
  1061. // {
  1062. // ch[i] = Msg[index+i];
  1063. // }
  1064. //
  1065. // lenID = AsciiToBYTE(ch[1]) + AsciiToBYTE(ch[2]) + AsciiToBYTE(ch[3]);
  1066. // lenID = lenID%16;
  1067. // lenID = ~lenID + 1;
  1068. //
  1069. // if (AsciiToBYTE(ch[0]) == lenID)
  1070. // {
  1071. // return TRUE;
  1072. // }
  1073. // else
  1074. // {
  1075. // return FALSE;
  1076. // }
  1077. //}
  1078. WORD CDataMate3000::RtnCheck(char Msg[VAR_MSG])
  1079. {
  1080. int len ,index;
  1081. len = 2;
  1082. index = 7;
  1083. char ch[2];
  1084. ch[0] = Msg[index];
  1085. ch[1] = Msg[index+1];
  1086. if (atoi(ch)==ERR_CID_RTN_VAR)
  1087. {
  1088. return ERR_CID_RTN_VAR;
  1089. }
  1090. else if (atoi(ch)==ERR_CID_RTN_CHKSUM)
  1091. {
  1092. return ERR_CID_RTN_CHKSUM;
  1093. }
  1094. else if (atoi(ch)==ERR_CID_RTN_LCHKSUM)
  1095. {
  1096. return ERR_CID_RTN_LCHKSUM;
  1097. }
  1098. else if (atoi(ch)==ERR_CID_RTN_CID2)
  1099. {
  1100. return ERR_CID_RTN_CID2;
  1101. }
  1102. else if (atoi(ch)==ERR_CID_RTN_FORMAT)
  1103. {
  1104. return ERR_CID_RTN_FORMAT;
  1105. }
  1106. else if (atoi(ch)==ERR_CID_RTN_INVALI_DATA)
  1107. {
  1108. return ERR_CID_RTN_INVALI_DATA;
  1109. }
  1110. else /*if (atoi(ch)==ERR_CID_RTN_NORMAL)*/
  1111. {
  1112. return ERR_CID_RTN_NORMAL;
  1113. }
  1114. }