leicai.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*************************************************
  2. /* Copyright (C), 2010-2011,StoneU. Co., Ltd.
  3. /* File name: leicai.h
  4. /* Author: Zero.t
  5. /* Version: Ver1.0.0.1
  6. /* Date: 2011-12-05
  7. /* Description: 镭彩科技带大显示屏温湿度;
  8. /* Others: RS232,2400/8/1,无校验;
  9. /* Function List: ###
  10. /* History:
  11. /* 特别说明: 该协议 项目:上海 捷明信息
  12. *************************************************/
  13. #ifndef _LEICAI_UPS_HEAD__
  14. #define _LEICAI_UPS_HEAD__
  15. #pragma once
  16. #include "CommInterface.h"
  17. class leicai:public CCommInterface
  18. {
  19. public:
  20. enum __ERRO_CODE_UPSSANTAK
  21. {
  22. ERR_CODE_LEICAI_COM_FAULT = 50201 , //设备串口通信故障
  23. ERR_CODE_LEICAI_COM_BUSY , //设备串口通信忙
  24. ERR_CODE_LEICAI_COM_READ_NO_DATA , //设备没有读到数据
  25. ERR_CODE_LEICAI_COM_READ_LEN_OVER , //设备读到数据长度超时限制
  26. ERR_CODE_LEICAI_COM_LRC_LOST , //设备lrc校验失败
  27. EER_CODE_LEICAI_COM_WRITE_DATA , //设备写串口错误
  28. EER_CODE_LEICAI_COM_REGNUM , //设备寄存器数
  29. ERR_CODE_LEICAI_COM_VARLEN , //设备变量长度非法
  30. ERR_CODE_LEICAI_COM_INVALIDRES , //设备无效应答
  31. };
  32. #define DEBUG_LEICAI 1
  33. public:
  34. leicai(char *szPath,char *szIniName,int nCommPort,int nAddr,int nRate,int nDataBit,int nStopBit,int nParity,int nInterval);
  35. ~leicai(void);
  36. BOOL leicaiOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval);
  37. int SendReadRequest(
  38. char *szPath, // 程序所在路径
  39. char *szIniName, // 配置文件名称
  40. int nCommPort, // 串行端口
  41. int nAddr, // 设备地址
  42. char *szCmd, // 请求命令
  43. char *szMsg, // 响应的值
  44. int nReversed1, // 预留整形参数1接口
  45. int nReversed2, // 预留整形参数2接口
  46. int nReversed3, // 预留整形参数3接口
  47. int nReversed4, // 预留整形参数4接口
  48. int nReversed5, // 预留整形参数5接口
  49. float fReversed1, // 预留float参数1接口
  50. float fReversed2, // 预留float参数2接口
  51. float fReversed3, // 预留float参数3接口
  52. char *szReversed1, // 预留字符数组参数1接口
  53. char *szReversed2, // 预留字符数组参数2接口
  54. char *szReversed3, // 预留字符数组参数3接口
  55. char *szReversed4, // 预留字符数组参数4接口
  56. char *szReversed5 // 预留字符数组参数5接口
  57. );
  58. // 发送设置设备参数请求
  59. int SendSetReuest(
  60. char *szPath, // 程序所在路径
  61. char *szIniName, // 配置文件名称
  62. int nCommPort, // 串行端口
  63. int nAddr, // 设备地址
  64. char *szCmd, // 请求命令
  65. char *szSetMsg, // 设置的值
  66. int nReversed1, // 预留整形参数1接口
  67. int nReversed2, // 预留整形参数2接口
  68. int nReversed3, // 预留整形参数3接口
  69. int nReversed4, // 预留整形参数4接口
  70. int nReversed5, // 预留整形参数5接口
  71. float fReversed1, // 预留float参数1接口
  72. float fReversed2, // 预留float参数2接口
  73. float fReversed3, // 预留float参数3接口
  74. char *szReversed1, // 预留字符数组参数1接口
  75. char *szReversed2, // 预留字符数组参数2接口
  76. char *szReversed3, // 预留字符数组参数3接口
  77. char *szReversed4, // 预留字符数组参数4接口
  78. char *szReversed5 // 预留字符数组参数5接口
  79. );
  80. protected:
  81. int GetDeviceParam( int nAddr,CCommProcess *pComm,char *IniSendCMD,const int &IniSendlen);
  82. int Send_ReadDeviceData(int nAddr,CCommProcess *pComm, const char *IniSendCMD,const int &IniSendlen);
  83. int Recv_ReadDeviceData(int nAddr,CCommProcess *pComm,char *szSendCMD);
  84. int SetDeviceParam( int nAddr,CCommProcess *pComm,char *szCmd,char *szSetMsg,char *szRecvMsg,char *IniSendCMD, const int &IniSendlen);
  85. int Send_WriteDeviceData(int naddr, CCommProcess *pComm, char *szCmd, char *szSetMsg, char *IniSendCMD, const int &IniSendlen );
  86. int Recv_WriteDeviceData(int nAddr, CCommProcess *pComm, char *szCmd, char *szRecvMsg );
  87. private:
  88. int Getleicai_Msg( int nAddr,char *szSendCMD, char *szMsg,int &nIndex,int &nLen,char *szType,int startBit,int endBit );
  89. void Setleicai_Msg( int nAddr, char *szSendCMD, char *pBuffer);
  90. void GetSystemTime(BYTE *szSystemTime);
  91. void SimulationCommData();
  92. int StrLower(char *pSource, char *pDest);
  93. private:
  94. BOOL m_dwOnlineTick[MAX_ADDR];
  95. BOOL m_devOnline[MAX_ADDR];
  96. HANDLE m_hSemComm;
  97. CRITICAL_SECTION m_csReadMsg;
  98. char m_sz_Msg[MAX_ADDR][MAX_RECE_MSG];
  99. };
  100. #endif