

typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef uint64_t QWORD;

#define IDENTIFY_HEADER 0x5A3577A5
#define USBIO_LIBRARY_VERSION "1.0.0"

#define USBIO_V2    0x1000
#define USBIO_V2_11 0x1100
#define USBIO_V2_12 0x1200
#define USBIO_V2_13 0x1300
#define USBIO_V2_14 0x1400
#define USBIO_V2_15 0x1500
#define USBIO_V2_16 0x1600
#define USBIO_V2_17 0x1700

// USB-2200 Device ID
#define USB2245     (USBIO_V2 + 0x45)
#define USB2245_32  (USBIO_V2_11 + 0x45)
#define USB2251     (USBIO_V2 + 0x51)
#define USB2251_32  (USBIO_V2_11 + 0x51)
#define USB2251_64  (USBIO_V2_12 + 0x51)
#define USB2255     (USBIO_V2 + 0x55)
#define USB2255_32  (USBIO_V2_11 + 0x55)
#define USB2255_64  (USBIO_V2_12 + 0x55)
#define USB2260_24  (USBIO_V2 + 0x60)
#define USB2260A_24 (USBIO_V2_11 + 0x60)
#define USB2260B_24 (USBIO_V2_12 + 0x60)
#define USB2260C_24 (USBIO_V2_13 + 0x60)
#define USB2260_48  (USBIO_V2_14 + 0x60)
#define USB2260A_48 (USBIO_V2_15 + 0x60)
#define USB2260B_48 (USBIO_V2_16 + 0x60)
#define USB2260C_48 (USBIO_V2_17 + 0x60)
#define USB2261_16  (USBIO_V2 + 0x61)
#define USB2261A_16 (USBIO_V2_11 + 0x61)
#define USB2261B_16 (USBIO_V2_12 + 0x61)
#define USB2261C_16 (USBIO_V2_13 + 0x61)
#define USB2261_32  (USBIO_V2_14 + 0x61)
#define USB2261A_32 (USBIO_V2_15 + 0x61)
#define USB2261B_32 (USBIO_V2_16 + 0x61)
#define USB2261C_32 (USBIO_V2_17 + 0x61)

#define USB2217H    (USBIO_V2_11 + 0x17)
#define USB2224     (USBIO_V2 + 0x24)

#define USB2264     (USBIO_V2 + 0x64)
#define USB2264_16  (USBIO_V2_11 + 0x64)
#define USB2268     (USBIO_V2 + 0x68)
#define USB2268_18  (USBIO_V2_11 + 0x68)
// USB-2200 Device ID end

#define OPEN_PARAM_ERR        -3
#define TOO_MANY_DEVICES_ERR  -2
#define DEV_NOTEXISTS_ERR     -1
#define NO_ERR                0
#define OPENDIR_ERR           1
#define DEV_NOTOPEN_ERR       2
#define MODULE_INIT_ERR       3
#define IDENTIFY_HEADER_ERR   4
#define WRITE_BYTECOUNT_ERR   5
#define READ_BYTECOUNT_ERR    6
#define INVALID_PARAM_ERR     7
#define INVALID_HANDLE_ERR    8

int USB2200_ListDevice();
int USB2200_OpenDevice(WORD pid, BYTE bid);
WORD USB2200_CloseDevice(int handle);
char* USBIO_GetLibraryVersion(void);
WORD USB2200_LoadDefault(int handle);
WORD USB2200_SetDeviceNickName(int handle, const char *desc);
WORD USB2200_GetDeviceNickName(int handle, char *desc);
WORD USB2200_SetSoftWDTTimeout(int handle, DWORD timeout);
WORD USB2200_GetSoftWDTTimeout(int handle, DWORD *timeout);
WORD USB2200_SYNCDevice(int handle);
WORD USB2200_ClearWDTErrLED(int handle);
WORD USB2200_GetFwVer(int handle, WORD *FwVer);
WORD USB2200_GetFwDate(int handle, char *FwDate);
WORD USB2200_GetDOTotal(int handle, BYTE *o_byDOTotal);
WORD USB2200_GetDITotal(int handle, BYTE *o_byDITotal);
WORD USB2200_GetAOTotal(int handle, BYTE *o_byAOTotal);
WORD USB2200_GetAITotal(int handle, BYTE *o_byAITotal);
WORD USB2200_GetPOTotal(int handle, BYTE *o_byPOTotal);
WORD USB2200_GetPITotal(int handle, BYTE *o_byPITotal);

WORD USB2200_DO_WriteValue(int handle, QWORD val);
WORD USB2200_DO_WriteChannel(int handle, BYTE channel, BYTE val);
WORD USB2200_DO_ReadValue(int handle, QWORD *val);
WORD USB2200_DO_SetPowerOnEnable(int handle, QWORD val);
WORD USB2200_DO_SetPowerOnEnableToChannel(int handle, BYTE ch, BYTE bit);
WORD USB2200_DO_GetPowerOnEnable(int handle, QWORD *val);
WORD USB2200_DO_SetSafetyEnable(int handle, QWORD enable_mask, QWORD val);
WORD USB2200_DO_SetSafetyEnableChannel(int handle, BYTE ch, BYTE enable, BYTE val);
WORD USB2200_DO_GetSafetyEnable(int handle, QWORD *enable_mask, QWORD *val);
WORD USB2200_DO_SetInverse(int handle, BYTE val);
WORD USB2200_DO_GetInverse(int handle, BYTE *val);

WORD USB2200_DI_ReadValue(int handle, QWORD *val);
WORD USB2200_DI_ReadChannel(int handle, BYTE ch, BYTE *val);
WORD USB2200_DI_SetFilter(int handle, WORD val);
WORD USB2200_DI_GetFilter(int handle, WORD *val);
WORD USB2200_DI_SetInverse(int handle, BYTE val);
WORD USB2200_DI_GetInverse(int handle, BYTE *val);
WORD USB2200_DI_SetCntEdgeTrigger(int handle, BYTE val);
WORD USB2200_DI_GetCntEdgeTrigger(int handle, BYTE *val);
WORD USB2200_DI_ReadCounterValue(int handle, DWORD *counter_array, BYTE di_num);
WORD USB2200_DI_ReadChannelCounter(int handle, BYTE ch, DWORD *val);
WORD USB2200_DI_ClearCounter(int handle, QWORD clear_mask);
WORD USB2200_DI_ClearCounterChannel(int handle, BYTE channel);

