CIO.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "dt.h"
  3. #include "IIO.h"
  4. #include "CHardware.h"
  5. #include <string>
  6. #include <memory>
  7. #ifdef C_IO_EXPORTS
  8. #define C_IO_DLL_API __declspec(dllexport)
  9. #else
  10. #define C_IO_DLL_API //__declspec(dllimport)
  11. #endif
  12. class C_IO_DLL_API CIO
  13. {
  14. public:
  15. typedef struct
  16. {
  17. CIO* pClass;
  18. HANDLE hEvent;
  19. ns_db::DIGIT_IO_LEVEL level;
  20. ULONG lDleay;
  21. bool bRestore;
  22. } THREAD_CONFIG_STRUCT;
  23. private:
  24. ns_db::IO_CONFIG_STRUCT m_stIoConfig;
  25. bool m_bEnable = false;
  26. bool m_bIsInitSuccess = false;
  27. HANDLE m_hEvent = NULL;
  28. CDigitInput* m_pDi = nullptr;
  29. CDigitOutput* m_pDo = nullptr;
  30. CDigitInputS* m_pDis = nullptr;
  31. CDigitOutputS* m_pDos = nullptr;
  32. CAnalogOutput* m_pAo = nullptr;
  33. CAnalogInput* m_pAi = nullptr;
  34. public:
  35. CIO();
  36. LONG Init(ns_db::IO_CONFIG_STRUCT stIoConfig, void* pIO);
  37. string GetUtility();
  38. string GetName();
  39. string GetModuleType();
  40. LONG GetIo(ns_db::DIGIT_IO_LEVEL& nOutput);
  41. LONG GetIo(short & nOutput);
  42. LONG SetIo(ns_db::DIGIT_IO_LEVEL nOutput);
  43. LONG SetIo(short nOutput);
  44. //设置IO为高电平,如果lDelay>0时,将延时lDelay毫秒后自动恢复为设置前状态。
  45. //bRestore时间到后是否恢复,如果lDelay<=0,bRestore无意义
  46. LONG SetIo2LevelHigh(LONG lDelay,bool bRestore = false);
  47. //设置IO为高电平,如果lDelay>0时,将延时lDelay毫秒后自动恢复为设置前状态。
  48. //bRestore时间到后是否恢复,如果lDelay<=0,bRestore无意义
  49. LONG SetIo2LevelLow(LONG lDelay, bool bRestore = false);
  50. //等待设置Io线程完成
  51. LONG WaitSetIoThreadDone();
  52. static VOID CALLBACK threadSetIo(PTP_CALLBACK_INSTANCE Instance, PVOID Parameter, PTP_WORK Work);
  53. };