123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #pragma once
- #ifndef GPIOCLASSIMPL_DISTRBUSUSB_H
- #define GPIOCLASSIMPL_DISTRBUSUSB_H
- //#pragma pack(push,1)
- #include "GpioClass.h"
- #include "stdafx.h"
- //#include "log4vendor.h"
- using namespace std;
- #pragma pack(push,1)
- #define _DISTRBUSUSB_DEVICENAME "\\\\.\\DIO$"
- enum Method : int
- {
- /// <summary>
- /// Specifies the buffered I/O method, which is typically used for transferring
- /// small amounts of data per request. Most I/O control codes for device and
- /// intermediate drivers use this TransferType value.
- /// </summary>
- Buffered = 0,
- /// <summary>
- /// see Windows Device Driver Kit
- /// </summary>
- InDirect = 1,
- /// <summary>
- /// Specifed if the caller of DeviceIoControl will pass data to the
- /// driver.
- /// </summary>
- OutDirect = 2,
- /// <summary>
- /// Specifed if the caller of DeviceIoControl will receive data from
- /// the driver.
- /// </summary>
- Neither = 3
- };
- enum FileAccess
- {
- /// <summary>
- /// The I/O manager sends the IRP for any caller that has a handle to the file object
- /// that represents the target device object.
- /// </summary>
- Any = 0,
- /// <summary>
- /// Same as <see cref="Any"/>.
- /// </summary>
- Special = Any,
- /// <summary>
- /// The I/O manager sends the IRP only for a caller with read access rights, allowing
- /// the underlying device driver to transfer data from the device to system memory.
- /// </summary>
- Read = (0x0001), // file & pipe
- /// <summary>
- /// The I/O manager sends the IRP only for a caller with write access rights, allowing
- /// the underlying device driver to transfer data from system memory to its device.
- /// </summary>
- Write = (0x0002), // file & pipe
- };
- class GpioClassImpl : public GpioClass
- {
- public:
- GpioClassImpl();
- ~GpioClassImpl();
- //DeviceBaseClass
- virtual ErrorCodeEnum GetDevCategory(DevCategoryInfo &devCategory);
- virtual ErrorCodeEnum Reset();
- virtual ErrorCodeEnum DevClose();
- virtual ErrorCodeEnum GetLastErr(DevErrorInfo &devErrInfo);
- //GpioClass
- //
- // Device initialization.
- // Configure port input/output direction.
- //
- virtual ErrorCodeEnum DevOpen(GpioInitParam initParam);
- //
- // Set ports output.
- // Arguments:
- // - dwPort:port serial number,0~MAX_PORT_NUM-1
- // - btData:output value
- // bit value 1/0 means voltage high or low
- // ex.dwPort=0 btData=10001010 means set port 0's the 2nd,4th,8th pin output high
- //
- virtual ErrorCodeEnum WritePort(DWORD dwPort,BYTE btData);
- //
- // Get port input.
- // Arguments:
- // - dwPort:port serial number,0~MAX_PORT_NUM-1
- // - btStatus:input value
- // ex.dwPort=0 btStatus=10001010 means port 0's the 2nd,4th,8th pin with high level
- //
- virtual ErrorCodeEnum ReadPort(DWORD dwPort,BYTE &btStatus);
- private:
- bool m_bDevOpen;
- //std::string m_ComPort;
- //DWORD m_BaudRate;
- //CHAR m_szErrMsg[MAX_DEV_ERR_MSG];
- CHAR m_szErrMsg[MAX_DEV_ERROR_MSG_LEN];
- ErrorCodeEnum LightTurnOn();
- // void SaveErrorInfo(CHAR* errMsg, int errCode=95555);
- void SaveErrorInfo(CHAR* errMsg, int errCode, const CHAR* strFunc = NULL, int nLine = 0);
- int CtlCode( int deviceType, int function, int method, int access )
- {
- return ((deviceType) << 16) | ((access) << 14) | ((function) << 2) | (method);
- }
- public:
- CKEBA_DevCtrl *KEBA_DevCtrl;
- HANDLE m_hDistrBusUSB;
- DWORD m_dwPortNum;
- bool m_dir[MAX_PORT_NUM];
- int m_outputPortTotal;
- bool m_bIsUSBOn;
- int m_nUSBDelay;
- WORD m_wDevStatus;
- const int PDD_DIO_CATEGORY;
- // I:
- // O: # of inports, # of outports
- const int PDD_DIO_QUERY;
- // I:
- // O: 32 bit inports, 32 bit outport
- const int PDD_DIO_READ;
- // I: 32 bit update bit mask, 32 bit outports bit vector
- // O: 32 bit inports bit vector, 32 bit outports bit vector
- const int PDD_DIO_WRITE_INT;
- //bool CreateDevMutex();
- private:
- void intToByte(int i, BYTE* buf, UINT uOffset);
- int bytesToInt(BYTE* bytes, UINT uOffset);
- // CHAR m_sIniPath[MAX_PATH];
- };
- #endif // GPIOCLASSIMPL_DISTRBUSUSB_H
- #pragma pack(pop)
|