jb1506.cpp 30 KB

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