ILamp.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. //#pragma warning(disable:4251)
  3. #include <vector>
  4. #include <mutex>
  5. #include "string.h"
  6. #include"CRS232.h"
  7. #ifdef LAMP_EXPORTS
  8. #define LAMP_DLL_API __declspec(dllexport)
  9. #else
  10. #define LAMP_DLL_API //__declspec(dllimport)
  11. #endif
  12. typedef struct _LIGHT_STRUCT
  13. {
  14. int ChannelIndex;
  15. int LightValue;
  16. }LIGHT_STRUCT;
  17. //设备类型
  18. enum Lamp_Ctltype { LAMP_CST = 1 , LIGTH_HONGREN};
  19. #define LIGTH_BASE_ERROR (SERIAL_PORT_BASE_ERROR+10000)
  20. typedef enum
  21. {
  22. DEVICE_BASE_FAIL = LIGTH_BASE_ERROR,
  23. LIGTH_TYPE_FAIL,
  24. //RTU_ERR_ORDER,
  25. //RTU_ERR_ADDR,
  26. //RTU_ERR_DATA,
  27. //RTU_ERR_CONN,
  28. //RTU_ERR_WRITE,
  29. //RTU_ERR_READ_NULL,
  30. //RTU_ERR_RECV,
  31. //RTU_ERR_PARITY,
  32. COM_PORT_FAIL,
  33. } LIGTHERR;
  34. class LAMP_DLL_API ILamp
  35. {
  36. public:
  37. typedef struct _LIGHT_STRUCT
  38. {
  39. string addrs;
  40. ILamp* pLigth;
  41. }ILAMP_LST;
  42. protected:
  43. bool m_bIsInitSuccess;
  44. Lamp_Ctltype m_iLightType; //设备类型
  45. string m_strLightName;
  46. bool m_bEnable; //灯光控制器禁止/启用
  47. ILamp(Lamp_Ctltype iLightType,string strLightName);
  48. ~ILamp();
  49. public:
  50. // 获取单实例对象
  51. static long GetInstance(const char* ipAddress, Lamp_Ctltype iLigthType, ILamp **ligth);
  52. virtual string GetErrText(long errid);
  53. virtual long Init(unsigned long iPort); //初始化
  54. virtual long Init(const char* ipAddress); //初始化
  55. virtual void UnInit() = 0;//关闭
  56. bool IsInitSuccess() { return m_bIsInitSuccess; };
  57. public:
  58. virtual long SetLight(std::vector<LIGHT_STRUCT> vecLight, unsigned char iMaxSendNum = 3) = 0;
  59. virtual long SetLight(int ChannelIndex, int LightValue, unsigned char iMaxSendNum = 3) = 0;
  60. virtual long GetLight(int ChannelIndex,int &LightValue, unsigned char iMaxSendNum = 3) = 0;
  61. private:
  62. static std::mutex m_Mutex;
  63. static std::vector<ILamp::ILAMP_LST> m_vecLamp;
  64. static ILamp* GetLamp(string addrs);
  65. };