5 #define USBRL_API __declspec(dllexport)
6 #include "../usb_relay_device.h"
7 #include "../usb_relay_hw.h"
12 #pragma comment(lib, "setupapi")
13 #pragma comment(lib, "hid")
20 #define dbgprintf(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
21 //#define dbgprintf(fmt, ...) printf(fmt, __VA_ARGS__)
22 //#define dbgprintf(fmt, ...) __noop(fmt, __VA_ARGS__)
33 /** Initialize the USB Relay Library
34 @returns: This function returns 0 on success and -1 on error.
36 int USBRL_API
usb_relay_init(void)
38 dbgprintf("Init lib\n");
42 /** Finalize the USB Relay Library.
43 This function frees all of the static data associated with USB Relay Library.
44 It should be called at the end of execution to avoid memory leaks.
45 @returns: This function returns 0 on success and -1 on error.
47 int USBRL_API
usb_relay_exit(void)
52 /** Enumerate the USB Relay Devices.*/
53 struct usb_relay_device_info USBRL_API
* usb_relay_device_enumerate(void)
59 /** Free an enumeration Linked List*/
60 void USBRL_API
usb_relay_device_free_enumerate(struct usb_relay_device_info
*di
)
65 /** Open device by serial number
66 @return: This function returns a valid handle to the device on success or NULL on failure.
67 Example: usb_relay_device_open_with_serial_number("abcde", 5) */
68 intptr_t USBRL_API
usb_relay_device_open_with_serial_number(const char *serial_number
, unsigned len
)
73 /* Open a USB relay device
74 @return: This function returns a valid handle to the device on success or NULL on failure.
76 intptr_t USBRL_API
usb_relay_device_open(struct usb_relay_device_info
*device_info
)
81 /* Close a USB relay device*/
82 void USBRL_API
usb_relay_device_close(intptr_t hHandle
)
87 /** Turn ON a relay channel on the USB-Relay-Device
88 @param index -- which channel your want to open
89 @param hHandle -- which usb relay device your want to operate
90 @returns: 0 -- success; 1 -- error; 2 -- index is outnumber the number of the usb relay device
92 int USBRL_API
usb_relay_device_open_one_relay_channel(intptr_t hHandle
, int index
)
97 /** Turn ON all relay channels on the USB-Relay-Device
98 @param hHandle -- which usb relay device your want to operate
99 @returns: 0 -- success; 1 -- error
101 int USBRL_API
usb_relay_device_open_all_relay_channel(intptr_t hHandle
)
106 /** Turn OFF a relay channel on the USB-Relay-Device
107 @param index -- which channel your want to close
108 @paramhHandle -- which usb relay device your want to operate
109 @returns: 0 -- success; 1 -- error; 2 -- index is outnumber the number of the usb relay device
111 int USBRL_API
usb_relay_device_close_one_relay_channel(intptr_t hHandle
, int index
)
116 /** Turn OFF all relay channels on the USB-Relay-Device
117 @paramter: hHandle -- which usb relay device your want to operate
118 @returns: 0 -- success; 1 -- error
120 int USBRL_API
usb_relay_device_close_all_relay_channel(intptr_t hHandle
)
126 Status bits: one bit indicate a relay status.
127 bit 0/1/2/3/4/5/6/7/8 indicate channel 1/2/3/4/5/6/7/8 status
128 1 -- means ON, 0 -- means OFF.
129 @returns: 0 -- success; 1 -- error
131 int USBRL_API
usb_relay_device_get_status(intptr_t hHandle
, unsigned int *status
)