GpioClassImpl_DistrBusUSB.h 4.1 KB

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