hipulse_uv130.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. #include "stdafx.h"
  2. #include "hipulse_uv130.h "
  3. hipulse_uv130::hipulse_uv130(char *szPath,char *szIniName,int nCommPort,int nAddr,int nRate,int nDataBit,int nStopBit,int nParity,int nInterval)
  4. {
  5. #if IS_USE_READMSG_CS
  6. InitializeCriticalSection( &m_csReadMsg ); //初始化一个临界资源对象
  7. #endif
  8. MTVERIFY( m_hSemComm = CreateEvent( NULL, TRUE, TRUE, 0) ); //CreateEvent()创建或打开一个命名的或无名的事件对象
  9. for( int i = 0; i < MAX_ADDR; i++ )
  10. {
  11. memset(m_szHipulse_U_41Msg[i], 0, sizeof(m_szHipulse_U_41Msg[i]));
  12. memset(m_szHipulse_U_43Msg[i], 0, sizeof(m_szHipulse_U_43Msg[i]));
  13. memset(m_szHipulse_U_44Msg[i], 0, sizeof(m_szHipulse_U_44Msg[i]));
  14. memset(m_szHipulse_U_E1Msg[i], 0, sizeof(m_szHipulse_U_E1Msg[i]));
  15. memset(m_szHipulse_U_E2Msg[i], 0, sizeof(m_szHipulse_U_E2Msg[i]));
  16. memset(m_szHipulse_U_E3Msg[i], 0, sizeof(m_szHipulse_U_E3Msg[i]));
  17. m_devOnline[i] = TRUE;
  18. m_dwOnlineTick[i] = 0;
  19. }
  20. }
  21. hipulse_uv130::~hipulse_uv130()
  22. {
  23. #if IS_USE_READMSG_CS
  24. DeleteCriticalSection( &m_csReadMsg );
  25. #endif
  26. MTVERIFY( CloseHandle( m_hSemComm ) );
  27. CloseComm();
  28. }
  29. BOOL hipulse_uv130::UpsHipulseOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  30. {
  31. BOOL bResult = FALSE;
  32. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  33. //LOG4C((LOG_NOTICE,"->OpenUPSComm"));
  34. return bResult;
  35. }
  36. int hipulse_uv130::GetIniInfo(char *szPath,char *szIniName,char *szCmd,char *IniSendCMD,int &IniSendlen,char *szDataType,int &nIndex,int &nLen, int &iSBit, int &iEBit)
  37. {
  38. CHAR szFile[MAX_PATH + 1] = "";
  39. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
  40. IniSendlen = GetPrivateProfileString(szCmd, "SendCmd", "", IniSendCMD, 10, szFile); // 返回的字符串是以\0结束的;
  41. GetPrivateProfileString(szCmd, "type", "", szDataType, 10, szFile);
  42. szDataType[strlen(szDataType)] = '\0';
  43. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
  44. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  45. iSBit = GetPrivateProfileInt(szCmd, "StaBit", 0, szFile);//从配置文件中取值
  46. iEBit = GetPrivateProfileInt(szCmd, "EndBit", 0, szFile);
  47. return 0;
  48. }
  49. // 发送读取设备参数请求
  50. int hipulse_uv130::SendReadRequest(
  51. char szPath[MAX_PATH], // 程序所在路径
  52. char szIniName[MAX_PATH], // 配置文件名称
  53. int nCommPort, // 串行端口
  54. int nAddr, // 设备地址
  55. char szCmd[MAX_CMD], // 请求命令
  56. char szMsg[VAR_MSG], // 响应的值
  57. int nReversed1, // 预留整形参数1接口
  58. int nReversed2, // 预留整形参数2接口
  59. int nReversed3, // 预留整形参数3接口
  60. int nReversed4, // 预留整形参数4接口
  61. int nReversed5, // 预留整形参数5接口
  62. float fReversed1, // 预留float参数1接口
  63. float fReversed2, // 预留float参数2接口
  64. float fReversed3, // 预留float参数3接口
  65. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  66. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  67. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  68. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  69. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  70. )
  71. {
  72. //LOG4C((LOG_NOTICE,"->SendReadRequest"));
  73. CCommProcess *pComm = FindComm(nCommPort);
  74. if( pComm == NULL ) return -1;
  75. int nRet = -1;
  76. int nIndex(0), nLen(0), IniSendlen(0),iSBit(0), iEBit(0);
  77. char IniSendCMD[MAX_CMD] = {0}, szDataType[CMD_TYPE] = {0};
  78. GetIniInfo(szPath,szIniName,szCmd,IniSendCMD,IniSendlen,szDataType,nIndex,nLen,iSBit,iEBit);
  79. if( nAddr < 1 )
  80. return -1;
  81. int iCmd = atoi(szCmd + 4);
  82. if(
  83. (strlen(m_szHipulse_U_41Msg[nAddr -1]) == 0 && (iCmd >= 1 && iCmd <= 14)) || iCmd == 1 ||
  84. (strlen(m_szHipulse_U_E1Msg[nAddr -1]) == 0 && (iCmd >= 15 && iCmd <= 28)) || iCmd == 15 ||
  85. (strlen(m_szHipulse_U_E2Msg[nAddr -1]) == 0 && (iCmd >= 29 && iCmd <= 44)) || iCmd == 29 ||
  86. (strlen(m_szHipulse_U_E3Msg[nAddr -1]) == 0 && (iCmd >= 45 && iCmd <= 61)) || iCmd == 45 ||
  87. (strlen(m_szHipulse_U_43Msg[nAddr -1]) == 0 && (iCmd >= 62 && iCmd <= 74)) || iCmd == 62 ||
  88. (strlen(m_szHipulse_U_44Msg[nAddr -1]) == 0 && (iCmd >= 75 && iCmd <= 134)) || iCmd == 75
  89. )
  90. {
  91. nRet = GetDeviceParam( nAddr,pComm, szCmd, IniSendCMD, IniSendlen );
  92. if ( nRet != 0) return nRet;
  93. }
  94. if( GetTickCount() - m_dwOnlineTick[nAddr - 1] > 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 )
  95. m_devOnline[nAddr - 1] = FALSE;
  96. else if( GetTickCount() - m_dwOnlineTick[nAddr - 1] < 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 )
  97. m_devOnline[nAddr - 1] = TRUE;
  98. if( m_devOnline[nAddr - 1] == FALSE )
  99. return -1;
  100. nRet = GetHipulseQ41VarMsg( nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  101. nRet = GetHipulseQ43VarMsg( nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  102. nRet = GetHipulseQ44VarMsg( nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  103. nRet = GetHipulseQE1VarMsg( nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  104. nRet = GetHipulseQE2VarMsg( nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  105. nRet = GetHipulseQE3VarMsg( nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  106. //LOG4C((LOG_NOTICE,"nRet = %d,cmd = %s,值 = %s",nRet,szCmd,szMsg));
  107. return nRet;
  108. }
  109. int hipulse_uv130::GetDeviceParam(int nAddr,CCommProcess *pComm,char *szCmd,char *IniSendCMD,const int &IniSendlen)
  110. {
  111. int nRet = -1;
  112. nRet = Send_ReadDeviceData(nAddr, pComm, szCmd, IniSendCMD, IniSendlen);
  113. if( nRet != 0 )
  114. return nRet; // 串口忙
  115. nRet = Recv_ReadDeviceData( nAddr, pComm, szCmd);
  116. return nRet;
  117. }
  118. // 发送设置设备参数请求
  119. int hipulse_uv130::SendSetReuest(
  120. char szPath[MAX_PATH], // 程序所在路径
  121. char szIniName[MAX_PATH], // 配置文件名称
  122. int nCommPort, // 串行端口
  123. int nAddr, // 设备地址
  124. char szCmd[MAX_CMD], // 请求命令
  125. char szMsg[VAR_MSG], // 响应的值
  126. int nReversed1, // 预留整形参数1接口
  127. int nReversed2, // 预留整形参数2接口
  128. int nReversed3, // 预留整形参数3接口
  129. int nReversed4, // 预留整形参数4接口
  130. int nReversed5, // 预留整形参数5接口
  131. float fReversed1, // 预留float参数1接口
  132. float fReversed2, // 预留float参数2接口
  133. float fReversed3, // 预留float参数3接口
  134. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  135. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  136. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  137. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  138. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  139. )
  140. {
  141. return 0;
  142. }
  143. int hipulse_uv130::Send_ReadDeviceData(int nAddr,CCommProcess *pComm,char *szCmd, const char *IniSendCMD,const int &IniSendlen)
  144. {
  145. #if DEBUG_Hipulse_U
  146. char chLength[4] = {0};
  147. char chChkSum[5] = {0};
  148. REQUESTPARAM RequestPara;
  149. int iLen = sizeof(RequestPara);
  150. memset( &RequestPara, 0, iLen );
  151. RequestPara.RequestChild.bySoi = 0x7E;
  152. RequestPara.RequestChild.byVer[0] = 0x31;
  153. RequestPara.RequestChild.byVer[1] = 0x31;
  154. RequestPara.RequestChild.byAdr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
  155. RequestPara.RequestChild.byAdr[1] = ByteToAscii(nAddr & 0x0f);
  156. RequestPara.RequestChild.byCid1[0] = 0x32;
  157. RequestPara.RequestChild.byCid1[1] = 0x41;
  158. memcpy(RequestPara.RequestChild.byCid2, IniSendCMD, IniSendlen);
  159. RequestPara.RequestChild.byLength[0] = 0x30;
  160. RequestPara.RequestChild.byLength[1] = 0x30;
  161. RequestPara.RequestChild.byLength[2] = 0x30;
  162. RequestPara.RequestChild.byLength[3] = 0x30;
  163. int nLen = sizeof(RequestPara.byCheckSum) -1;
  164. BYTE *pDataBuf = new BYTE[ iLen - nLen];
  165. memset(pDataBuf, 0, iLen -nLen );
  166. memcpy(pDataBuf, &RequestPara, iLen - nLen);
  167. GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.byCheckSum) - 2 );
  168. delete []pDataBuf;
  169. pDataBuf = NULL;
  170. RequestPara.byCheckSum[0] = chChkSum[0];
  171. RequestPara.byCheckSum[1] = chChkSum[1];
  172. RequestPara.byCheckSum[2] = chChkSum[2];
  173. RequestPara.byCheckSum[3] = chChkSum[3];
  174. RequestPara.byEoi = 0x0D;
  175. if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口
  176. {
  177. int nDataLen = (int)sizeof(RequestPara);
  178. ResetEvent( m_hSemComm );
  179. int nResult = pComm->Write((BYTE *)&RequestPara, nDataLen);
  180. if( nResult != nDataLen )
  181. {
  182. SetEvent( m_hSemComm );
  183. return ERR_CODE_HIPULSE_COM_REGNUM;
  184. }
  185. }
  186. else
  187. {
  188. return ERR_CODE_HIPULSE_COM_BUSY;
  189. }
  190. #endif
  191. return 0;
  192. }
  193. int hipulse_uv130::Recv_ReadDeviceData(int nAddr,CCommProcess *pComm,char *szCmd)
  194. {
  195. #if DEBUG_Hipulse_U
  196. BYTE *byAryRecv = new BYTE[250];
  197. ZeroMemory(byAryRecv, 250);
  198. int iRecvLen = pComm->Read((BYTE *)byAryRecv, 250);
  199. if( iRecvLen <= 0)
  200. {
  201. SetEvent( m_hSemComm );
  202. if( iRecvLen != NULL)
  203. {
  204. delete[] byAryRecv;
  205. byAryRecv = NULL;
  206. }
  207. return ERR_CODE_HIPULSE_COM_READ_NO_DATA;
  208. }
  209. if (!ChkSumCheck( (char*)byAryRecv,iRecvLen))
  210. {
  211. SetEvent( m_hSemComm );
  212. if( iRecvLen != NULL)
  213. {
  214. delete[] byAryRecv;
  215. byAryRecv = NULL;
  216. }
  217. return ERR_CODE_HIPULSE_COM_CHKSUM_LOST;
  218. }
  219. #if 1
  220. if (!CheckLength( (char*)byAryRecv))
  221. {
  222. // 数据长度校检错误
  223. //TRACE("数据长度校检错误!\r\n");
  224. SetEvent( m_hSemComm );
  225. if( iRecvLen != NULL)
  226. {
  227. delete[] byAryRecv;
  228. byAryRecv = NULL;
  229. }
  230. return ERR_CODE_HIPULSE_COM_VARLEN;
  231. }
  232. int nRet = RtnCheck( (char*)byAryRecv,iRecvLen);
  233. if (nRet !=0 )
  234. {
  235. SetEvent( m_hSemComm );
  236. if( iRecvLen != NULL)
  237. {
  238. delete[] byAryRecv;
  239. byAryRecv = NULL;
  240. }
  241. return nRet;
  242. }
  243. #endif
  244. SetHipulseQ41VarMsg( nAddr,szCmd, (char*)byAryRecv);
  245. SetHipulseQ43VarMsg( nAddr,szCmd, (char*)byAryRecv);
  246. SetHipulseQ44VarMsg( nAddr,szCmd, (char*)byAryRecv);
  247. SetHipulseQE1VarMsg( nAddr,szCmd, (char*)byAryRecv);
  248. SetHipulseQE2VarMsg( nAddr,szCmd, (char*)byAryRecv);
  249. SetHipulseQE3VarMsg( nAddr,szCmd, (char*)byAryRecv);
  250. m_dwOnlineTick[nAddr -1] = GetTickCount();
  251. // 设置串口等待事件为有信号
  252. SetEvent( m_hSemComm );
  253. if( byAryRecv != NULL)
  254. {
  255. delete[] byAryRecv;
  256. byAryRecv = NULL;
  257. }
  258. #else
  259. SimulationCommData();
  260. #endif
  261. return 0;
  262. }
  263. void hipulse_uv130::SetHipulseQ41VarMsg( int nAddr,char *szCmd, char *pBuffer)
  264. {
  265. int iCmd = atoi(szCmd + 4);
  266. if ( iCmd >= 1 && iCmd <=14)
  267. {
  268. #if IS_USE_READMSG_CS
  269. EnterCriticalSection( &m_csReadMsg );
  270. #endif
  271. memcpy(m_szHipulse_U_41Msg[nAddr-1], pBuffer, sizeof(m_szHipulse_U_41Msg[nAddr-1]));
  272. #if IS_USE_READMSG_CS
  273. LeaveCriticalSection(&m_csReadMsg);
  274. #endif
  275. }
  276. }
  277. void hipulse_uv130::SetHipulseQE1VarMsg( int nAddr,char *szCmd, char *pBuffer)
  278. {
  279. int iCmd = atoi(szCmd + 4);
  280. if ( iCmd >= 15 && iCmd <=28)
  281. {
  282. #if IS_USE_READMSG_CS
  283. EnterCriticalSection( &m_csReadMsg );
  284. #endif
  285. memcpy(m_szHipulse_U_E1Msg[nAddr-1], pBuffer, sizeof(m_szHipulse_U_E1Msg[nAddr-1]));
  286. #if IS_USE_READMSG_CS
  287. LeaveCriticalSection(&m_csReadMsg);
  288. #endif;
  289. }
  290. }
  291. void hipulse_uv130::SetHipulseQE2VarMsg( int nAddr,char *szCmd, char *pBuffer)
  292. {
  293. int iCmd = atoi(szCmd + 4);
  294. if ( iCmd >= 29 && iCmd <=44)
  295. {
  296. #if IS_USE_READMSG_CS
  297. EnterCriticalSection( &m_csReadMsg );
  298. #endif
  299. memcpy(m_szHipulse_U_E2Msg[nAddr-1], pBuffer, sizeof(m_szHipulse_U_E2Msg[nAddr-1]));
  300. #if IS_USE_READMSG_CS
  301. LeaveCriticalSection(&m_csReadMsg);
  302. #endif;
  303. }
  304. }
  305. void hipulse_uv130::SetHipulseQE3VarMsg( int nAddr,char *szCmd, char *pBuffer)
  306. {
  307. int iCmd = atoi(szCmd + 4);
  308. if ( iCmd >= 45 && iCmd <=61)
  309. {
  310. #if IS_USE_READMSG_CS
  311. EnterCriticalSection( &m_csReadMsg );
  312. #endif
  313. memcpy(m_szHipulse_U_E3Msg[nAddr-1], pBuffer, sizeof(m_szHipulse_U_E3Msg[nAddr-1]));
  314. #if IS_USE_READMSG_CS
  315. LeaveCriticalSection(&m_csReadMsg);
  316. #endif
  317. }
  318. }
  319. void hipulse_uv130::SetHipulseQ43VarMsg( int nAddr,char *szCmd, char *pBuffer)
  320. {
  321. int iCmd = atoi(szCmd + 4);
  322. if ( iCmd >= 62 && iCmd <=74)
  323. {
  324. #if IS_USE_READMSG_CS
  325. EnterCriticalSection( &m_csReadMsg );
  326. #endif
  327. memcpy(m_szHipulse_U_43Msg[nAddr-1], pBuffer, sizeof(m_szHipulse_U_43Msg[nAddr-1]));
  328. #if IS_USE_READMSG_CS
  329. LeaveCriticalSection(&m_csReadMsg);
  330. #endif
  331. }
  332. }
  333. void hipulse_uv130::SetHipulseQ44VarMsg( int nAddr,char *szCmd, char *pBuffer)
  334. {
  335. int iCmd = atoi(szCmd + 4);
  336. if ( iCmd >= 75 && iCmd <=134)
  337. {
  338. #if IS_USE_READMSG_CS
  339. EnterCriticalSection( &m_csReadMsg );
  340. #endif
  341. memcpy(m_szHipulse_U_44Msg[nAddr-1], pBuffer, sizeof(m_szHipulse_U_44Msg[nAddr-1]));
  342. #if IS_USE_READMSG_CS
  343. LeaveCriticalSection(&m_csReadMsg);
  344. #endif;
  345. }
  346. }
  347. int hipulse_uv130::GetHipulseQ41VarMsg(int nAddr,char *szCmd, char *szRecvMsg,int &nIndex,int &nLen,char *szDataType)
  348. {
  349. int nRet = 0;
  350. int iCmd = atoi(szCmd + 4);
  351. if ( iCmd >= 1 && iCmd <=14)
  352. {
  353. #if IS_USE_READMSG_CS
  354. EnterCriticalSection( &m_csReadMsg );
  355. #endif
  356. DataConversion(szDataType, m_szHipulse_U_41Msg[nAddr-1] + nIndex, szRecvMsg, nLen, 0, 0);
  357. #if IS_USE_READMSG_CS
  358. LeaveCriticalSection(&m_csReadMsg);
  359. nRet = 0;
  360. #endif
  361. }
  362. return nRet;
  363. }
  364. int hipulse_uv130::GetHipulseQE1VarMsg(int nAddr,char *szCmd, char *szRecvMsg,int &nIndex,int &nLen,char *szDataType)
  365. {
  366. int nRet = 0;
  367. int iCmd = atoi(szCmd + 4);
  368. if ( iCmd >= 15 && iCmd <=28)
  369. {
  370. #if IS_USE_READMSG_CS
  371. EnterCriticalSection( &m_csReadMsg );
  372. #endif
  373. DataConversion(szDataType, m_szHipulse_U_E1Msg[nAddr-1] + nIndex, szRecvMsg, nLen, 0, 0);
  374. #if IS_USE_READMSG_CS
  375. LeaveCriticalSection(&m_csReadMsg);
  376. #endif
  377. nRet = 0;
  378. }
  379. return nRet;
  380. }
  381. int hipulse_uv130::GetHipulseQE2VarMsg(int nAddr,char *szCmd, char *szRecvMsg,int &nIndex,int &nLen,char *szDataType)
  382. {
  383. int nRet = 0;
  384. int iCmd = atoi(szCmd + 4);
  385. if ( iCmd >= 29 && iCmd <=44)
  386. {
  387. #if IS_USE_READMSG_CS
  388. EnterCriticalSection( &m_csReadMsg );
  389. #endif
  390. DataConversion(szDataType, m_szHipulse_U_E2Msg[nAddr-1] + nIndex, szRecvMsg, nLen, 0, 0);
  391. #if IS_USE_READMSG_CS
  392. LeaveCriticalSection(&m_csReadMsg);
  393. #endif
  394. nRet = 0;
  395. }
  396. return nRet;
  397. }
  398. int hipulse_uv130::GetHipulseQE3VarMsg(int nAddr,char *szCmd, char *szRecvMsg,int &nIndex,int &nLen,char *szDataType)
  399. {
  400. int nRet = 0;
  401. int iCmd = atoi(szCmd + 4);
  402. if ( iCmd >= 45 && iCmd <=61)
  403. {
  404. #if IS_USE_READMSG_CS
  405. EnterCriticalSection( &m_csReadMsg );
  406. #endif
  407. DataConversion(szDataType, m_szHipulse_U_E3Msg[nAddr-1] + nIndex, szRecvMsg, nLen, 0, 0);
  408. #if IS_USE_READMSG_CS
  409. LeaveCriticalSection(&m_csReadMsg);
  410. #endif
  411. nRet = 0;
  412. }
  413. return nRet;
  414. }
  415. int hipulse_uv130::GetHipulseQ43VarMsg(int nAddr,char *szCmd, char *szRecvMsg,int &nIndex,int &nLen,char *szDataType)
  416. {
  417. int nRet = 0;
  418. int iCmd = atoi(szCmd + 4);
  419. if ( iCmd >= 62 && iCmd <=74)
  420. {
  421. #if IS_USE_READMSG_CS
  422. EnterCriticalSection( &m_csReadMsg );
  423. #endif
  424. DataConversion(szDataType, m_szHipulse_U_43Msg[nAddr-1] + nIndex, szRecvMsg, nLen, 0, 0);
  425. #if IS_USE_READMSG_CS
  426. LeaveCriticalSection(&m_csReadMsg);
  427. #endif
  428. nRet = 0;
  429. }
  430. return nRet;
  431. }
  432. int hipulse_uv130::GetHipulseQ44VarMsg(int nAddr,char *szCmd, char *szRecvMsg,int &nIndex,int &nLen,char *szDataType)
  433. {
  434. int nRet = 0;
  435. int iCmd = atoi(szCmd + 4);
  436. if ( iCmd >= 75 && iCmd <=134)
  437. {
  438. #if IS_USE_READMSG_CS
  439. EnterCriticalSection( &m_csReadMsg );
  440. #endif
  441. DataConversion(szDataType, m_szHipulse_U_44Msg[nAddr-1] + nIndex, szRecvMsg, nLen, 0, 0);
  442. #if IS_USE_READMSG_CS
  443. LeaveCriticalSection(&m_csReadMsg);
  444. #endif
  445. nRet = 0;
  446. }
  447. return nRet;
  448. }
  449. void hipulse_uv130::SimulationCommData(void)
  450. {
  451. }
  452. UINT hipulse_uv130::GetCheckSum(char *pBuf, char chDest[5], int len)
  453. {
  454. WORD iSum = 0;;
  455. for(int i=0; i<len; i++)//求和
  456. {
  457. iSum += pBuf[i];
  458. }
  459. WORD iCompliment = iSum;
  460. iCompliment = ~iCompliment;//取反
  461. iCompliment++;
  462. itoa(iCompliment, chDest, 16);
  463. chDest[0] = lowercase2uppercase(chDest[0]);
  464. chDest[1] = lowercase2uppercase(chDest[1]);
  465. chDest[2] = lowercase2uppercase(chDest[2]);
  466. chDest[3] = lowercase2uppercase(chDest[3]);
  467. return atoi(chDest);
  468. }
  469. WORD hipulse_uv130::RtnCheck(char szRecvdMsg[VAR_MSG],int len)
  470. {
  471. char ch[2];
  472. ch[0] = szRecvdMsg[7];
  473. ch[1] = szRecvdMsg[8];
  474. if (atoi(ch) == 0)
  475. {
  476. return 0;
  477. }
  478. else if (atoi(ch)==ERR_CID_RTN_VAR)
  479. {
  480. return ERR_CID_RTN_VAR;
  481. }
  482. else if (atoi(ch)==ERR_CID_RTN_CHKSUM)
  483. {
  484. return ERR_CID_RTN_CHKSUM;
  485. }
  486. else if (atoi(ch)==ERR_CID_RTN_LCHKSUM)
  487. {
  488. return ERR_CID_RTN_LCHKSUM;
  489. }
  490. else if (atoi(ch)==ERR_CID_RTN_CID2)
  491. {
  492. return ERR_CID_RTN_CID2;
  493. }
  494. else if (atoi(ch)==ERR_CID_RTN_FORMAT)
  495. {
  496. return ERR_CID_RTN_FORMAT;
  497. }
  498. else if (atoi(ch)==ERR_CID_RTN_INVALI_DATA)
  499. {
  500. return ERR_CID_RTN_INVALI_DATA;
  501. }
  502. else if (atoi(ch)==ERR_CID_RTN_INVALI_RIGHT)
  503. {
  504. return ERR_CID_RTN_INVALI_RIGHT;
  505. }
  506. else if (atoi(ch)==ERR_CID_RTN_OPERATE_FALL)
  507. {
  508. return ERR_CID_RTN_OPERATE_FALL;
  509. }
  510. else if (atoi(ch)==ERR_CID_RTN_COM_ERR)
  511. {
  512. return ERR_CID_RTN_COM_ERR;
  513. }
  514. return -1;
  515. }