WorkStation.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #pragma once
  2. #include "LogicDevice.h"
  3. #include "commonDataStruct.h"
  4. #include "ScopeLock.h"
  5. #ifndef SYSTEMDEVICE_EXPORTS
  6. #ifdef _WIN64
  7. #ifdef _DEBUG
  8. #pragma comment(lib, "LogicDeviceX64D.lib")
  9. #else
  10. #pragma comment(lib, "LogicDeviceX64.lib")
  11. #endif
  12. #else
  13. #ifdef _DEBUG
  14. #pragma comment(lib, "LogicDeviceD.lib")
  15. #else
  16. #pragma comment(lib, "LogicDevice.lib")
  17. #endif
  18. #endif
  19. #endif
  20. #define CONNECTIONERROR 1
  21. #define UNCLEARERROR 2
  22. #define CLEARERROR 3
  23. #define AUTOCLEARERROR 4
  24. #ifdef SYSTEMDEVICE_EXPORTS
  25. #define SYSTEMDEVICE_API __declspec(dllexport)
  26. #else
  27. #define SYSTEMDEVICE_API __declspec(dllimport)
  28. #endif
  29. class SYSTEMDEVICE_API DeviceObject {
  30. public:
  31. DeviceObject();
  32. virtual ~DeviceObject();
  33. //打开设备
  34. int Open(string DeviceRootURI);
  35. int OpenDevice();
  36. //关闭设备
  37. int Close();
  38. int CloseDevice();
  39. RET_STATUS DeviceAction(const char* ActionName, ResDataObject& req, ResDataObject& res, DWORD timeout);
  40. const char* GetDeviceURI() { return m_strDeviceRoot.c_str(); }
  41. int GetAllDevice(ResDataObject& rdoAll);
  42. int GetDeviceUnitCount() { return m_nDeviceNum; }
  43. LogicClient* GetDeviceClient(int idx);
  44. LogicClient* GetDriverClient() { return m_pRootDriver; }
  45. protected:
  46. string m_strDeviceRoot;
  47. LogicClient *m_pRootDriver;
  48. ResDataObject m_DriverResource;
  49. ResDataObject m_DeviceList;
  50. int m_nDeviceNum;
  51. LogicClient* *m_pDevices;
  52. };
  53. /*
  54. * ROOT路径即设备的驱动URI,打开之后的设备URI是相对路径
  55. <DIOS_WS>
  56. <Default>
  57. <ServiceDevice>ServiceDefault</ServiceDevice>
  58. <OEMDevice>
  59. <ROOT>DIOS/DEVICE/DETECTOR/iRay/3543W/A876453</ROOT>
  60. <ROOT>DIOS/DEVICE/GENERATOR/Simens/Exs/B87632</ROOT>
  61. </OEMDevice>
  62. <SystemDevice>DRSystem</SystemDevice>
  63. </Default>
  64. <Demo>
  65. <ServiceDevice>ServiceDefault</ServiceDevice>
  66. <OEMDevice>
  67. <ROOT>DIOS/DEVICE/DETECTOR/ECOM/DEMO/DEMOFPD</ROOT>
  68. <ROOT>DIOS/DEVICE/GENERATOR/ECOM/DEMO/DEMOGEN</ROOT>
  69. </OEMDevice>
  70. <SystemDevice>DRSystem</SystemDevice>
  71. </Demo>
  72. </DIOS_WS>
  73. <ServiceDefault>
  74. <ROOT>DIOS/DEVICE/SERVICE/ImageSave/ECOM/1234</ROOT>
  75. <ROOT>DIOS/DEVICE/SERVICE/ImageView/ECOM/1234</ROOT>
  76. </ServiceDefault>
  77. <SystemDefault>
  78. <ROOT>DIOS/DEVICE/SYSTEM/DRSystem/ECOM/1234</ROOT>
  79. </SystemDefault>
  80. <DRSystem>
  81. <ROOT>DIOS/DEVICE/SYSTEM/DRSystem/ECOM/1234</ROOT>
  82. </DRSystem>
  83. */
  84. class SYSTEMDEVICE_API WorkStationDevice :
  85. public LogicDevice
  86. {
  87. protected:
  88. //ResDataObject* m_pResErrorList; //错误列表
  89. string m_strConfigFileName; //配置文件路径
  90. ResDataObject m_resAllConfig; //配置内容
  91. string m_strSetWS; //当前WorkStation名称
  92. BaseJsonDataObject<string> m_WorkSatition; //当前WorkStation对象
  93. int m_nAllOemDeviceNum;
  94. DeviceObject* m_pAllOemDevice; //工作位专用对象,如探测器+发生器
  95. int m_nServiceDeviceNum;
  96. DeviceObject* m_pServiceDevice; //服务设备
  97. int m_nSystemDeviceNum;
  98. DeviceObject* m_pSystemDevice; //系统设备
  99. vector<LogicClient*> m_pWSDriverClient;
  100. int m_nAllDeviceUnitNum;// 所有设备数量,包括服务设备和系统设备
  101. vector<LogicClient*> m_pWSDeviceClient; //所有的设备client事件句柄
  102. HANDLE* m_pHandleArray; // DeviceUnit通知事件数组,这里有漏洞,如果发生连续两个事件,会漏,使用者要两个都用:事件和轮询
  103. vector< string > m_vecWorksationDeviceUnitPath; //与Handle保持一致的事件对应的设备Path
  104. protected:
  105. bool RefreshUnitClientAttribute();
  106. RET_STATUS ResetFunc();
  107. void CloseUnit(const string& strPath);
  108. public: //对象对外接口
  109. //根据URI查找设备
  110. DeviceObject* FindDevice(string strDeviceURI);
  111. int GetAllDevice(ResDataObject& rdoAll);
  112. int OpenAll();
  113. int CloseAll();
  114. RET_STATUS RESET();
  115. RET_STATUS SetAction(const char* ActionName, ResDataObject& Req, ResDataObject& Resp, DWORD timeout = INFINITE);
  116. vector<string> GetAllDeviceDrivers(const char* ws = nullptr);
  117. void GetDriversNotifyHandle(HANDLE* pHandles, int nNum);
  118. vector<string> GetAllDeviceUnit();
  119. public:
  120. WorkStationDevice();
  121. virtual ~WorkStationDevice();
  122. //继承的接口实现
  123. virtual bool SYSTEM_CALL GetDeviceType(GUID& DevType) override;
  124. virtual RET_STATUS SYSTEM_CALL CmdToLogicDev(ResDataObject PARAM_IN* pCmd) override;
  125. RET_STATUS Request(ResDataObject PARAM_IN* pRequest, ResDataObject PARAM_OUT* pResponse) override;
  126. virtual RET_STATUS GetDeviceResource(ResDataObject PARAM_OUT* pDeviceResource) override;
  127. public: //模块对外接口
  128. //设置配置文件路径
  129. bool SetConfigFile(const char* pszFileName);
  130. bool SetConfigRes(ResDataObject &resConfig);
  131. //切换工作位
  132. RET_STATUS SetWorkStation(const char* pParam, int setWs = 1);
  133. //查询工作位
  134. RET_STATUS GetWorkStion(const char* pParam, ResDataObject &resWorkStation);
  135. RET_STATUS GetWorkStationList(ResDataObject& resWSList);
  136. //添加工作位
  137. RET_STATUS AddWorkStation(const char* pParam, ResDataObject &resWorkStation);
  138. //删除工作位
  139. RET_STATUS DelWorkStation(const char* pParam);
  140. //编辑工作位
  141. RET_STATUS EditWorkStation(const char* pParam, ResDataObject &resWorkStation);
  142. //检查工作位
  143. RET_STATUS CheckWorkStation(const char* pParam);
  144. //EBus版本WorkStation的Driver列表
  145. RET_STATUS GetDeviceDriver();
  146. RET_STATUS AddDriverList(const ResDataObject& pParam);
  147. RET_STATUS DelDriverList(const ResDataObject& pParam);
  148. RET_STATUS AddDeviceDriver(const ResDataObject& pParam);
  149. RET_STATUS DelDeviceDriver(const ResDataObject& pParam);
  150. RET_STATUS SetDeviceStatusAttr(const ResDataObject& pParam);
  151. bool CheckDriverDevice();
  152. RET_STATUS SetAS(const string& pParam);
  153. bool CheckASState(const char* ws = nullptr);
  154. // m_mapDeviceList有关的函数和定义,设备在线状态相关
  155. enum GetDevListOutType
  156. {
  157. otSaveXml,
  158. otGetDevDriver,
  159. };
  160. bool GetDeviceState() { return true; }
  161. vector<string> GetAllDevicesDemo();
  162. int GetAllDriversList(GetDevListOutType ot, ResDataObject& rdoOut);
  163. void ClearUnitClientList();
  164. void SetUnitClientToList(const char* pPath);
  165. bool UpdateUnitClientState(const char* pPath, int cmdtype);
  166. bool FindDeviceClient(const string& strDrv, LogicClient** ppClient);
  167. int InitDriverList();
  168. void IntUnitClientList(const string& strPath);
  169. bool CheckDevUnitErrorList();
  170. public:
  171. void CloseAllDeviceClient(); //关闭设备连接
  172. void CloseAllDriverClient(); //关闭驱动连接
  173. };