CIO.h 1.9 KB

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