GpioClassImpl_DistrBusUSB.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma once
  2. #ifndef GPIOCLASSIMPL_DISTRBUSUSB_H
  3. #define GPIOCLASSIMPL_DISTRBUSUSB_H
  4. #pragma pack(push,1)
  5. #include "GpioClass.h"
  6. #include "stdafx.h"
  7. //#include "log4vendor.h"
  8. using namespace std;
  9. #define _DISTRBUSUSB_DEVICENAME "\\\\.\\DIO$"
  10. enum Method : int
  11. {
  12. /// <summary>
  13. /// Specifies the buffered I/O method, which is typically used for transferring
  14. /// small amounts of data per request. Most I/O control codes for device and
  15. /// intermediate drivers use this TransferType value.
  16. /// </summary>
  17. Buffered = 0,
  18. /// <summary>
  19. /// see Windows Device Driver Kit
  20. /// </summary>
  21. InDirect = 1,
  22. /// <summary>
  23. /// Specifed if the caller of DeviceIoControl will pass data to the
  24. /// driver.
  25. /// </summary>
  26. OutDirect = 2,
  27. /// <summary>
  28. /// Specifed if the caller of DeviceIoControl will receive data from
  29. /// the driver.
  30. /// </summary>
  31. Neither = 3
  32. };
  33. enum FileAccess
  34. {
  35. /// <summary>
  36. /// The I/O manager sends the IRP for any caller that has a handle to the file object
  37. /// that represents the target device object.
  38. /// </summary>
  39. Any = 0,
  40. /// <summary>
  41. /// Same as <see cref="Any"/>.
  42. /// </summary>
  43. Special = Any,
  44. /// <summary>
  45. /// The I/O manager sends the IRP only for a caller with read access rights, allowing
  46. /// the underlying device driver to transfer data from the device to system memory.
  47. /// </summary>
  48. Read = (0x0001), // file & pipe
  49. /// <summary>
  50. /// The I/O manager sends the IRP only for a caller with write access rights, allowing
  51. /// the underlying device driver to transfer data from system memory to its device.
  52. /// </summary>
  53. Write = (0x0002), // file & pipe
  54. };
  55. class GpioClassImpl : public GpioClass
  56. {
  57. public:
  58. GpioClassImpl();
  59. ~GpioClassImpl();
  60. //DeviceBaseClass
  61. virtual ErrorCodeEnum GetDevCategory(DevCategoryInfo &devCategory);
  62. virtual ErrorCodeEnum Reset();
  63. virtual ErrorCodeEnum DevClose();
  64. virtual ErrorCodeEnum GetLastErr(DevErrorInfo &devErrInfo);
  65. //GpioClass
  66. //
  67. // Device initialization.
  68. // Configure port input/output direction.
  69. //
  70. virtual ErrorCodeEnum DevOpen(GpioInitParam initParam);
  71. //
  72. // Set ports output.
  73. // Arguments:
  74. // - dwPort:port serial number,0~MAX_PORT_NUM-1
  75. // - btData:output value
  76. // bit value 1/0 means voltage high or low
  77. // ex.dwPort=0 btData=10001010 means set port 0's the 2nd,4th,8th pin output high
  78. //
  79. virtual ErrorCodeEnum WritePort(DWORD dwPort,BYTE btData);
  80. //
  81. // Get port input.
  82. // Arguments:
  83. // - dwPort:port serial number,0~MAX_PORT_NUM-1
  84. // - btStatus:input value
  85. // ex.dwPort=0 btStatus=10001010 means port 0's the 2nd,4th,8th pin with high level
  86. //
  87. virtual ErrorCodeEnum ReadPort(DWORD dwPort,BYTE &btStatus);
  88. private:
  89. bool m_bDevOpen;
  90. //std::string m_ComPort;
  91. //DWORD m_BaudRate;
  92. //CHAR m_szErrMsg[MAX_DEV_ERR_MSG];
  93. CHAR m_szErrMsg[MAX_DEV_ERROR_MSG_LEN];
  94. ErrorCodeEnum LightTurnOn();
  95. void SaveErrorInfo(CHAR* errMsg, int errCode=95555);
  96. int CtlCode( int deviceType, int function, int method, int access )
  97. {
  98. return ((deviceType) << 16) | ((access) << 14) | ((function) << 2) | (method);
  99. }
  100. public:
  101. CKEBA_DevCtrl *KEBA_DevCtrl;
  102. HANDLE m_hDistrBusUSB;
  103. DWORD m_dwPortNum;
  104. bool m_dir[MAX_PORT_NUM];
  105. int m_outputPortTotal;
  106. bool m_bIsUSBOn;
  107. int m_nUSBDelay;
  108. WORD m_wDevStatus;
  109. const int PDD_DIO_CATEGORY;
  110. // I:
  111. // O: # of inports, # of outports
  112. const int PDD_DIO_QUERY;
  113. // I:
  114. // O: 32 bit inports, 32 bit outport
  115. const int PDD_DIO_READ;
  116. // I: 32 bit update bit mask, 32 bit outports bit vector
  117. // O: 32 bit inports bit vector, 32 bit outports bit vector
  118. const int PDD_DIO_WRITE_INT;
  119. //bool CreateDevMutex();
  120. private:
  121. void intToByte(int i, BYTE* buf, UINT uOffset);
  122. int bytesToInt(BYTE* bytes, UINT uOffset);
  123. CHAR m_sIniPath[MAX_PATH];
  124. };
  125. #endif // GPIOCLASSIMPL_DISTRBUSUSB_H
  126. #pragma pack(pop)