Windows DLL src added, vc2008
[usb-relay-hid.git] / lib / usb_relay_device.h
CommitLineData
8401c785 1#ifndef USB_RELAY_DEVICE_H__
2#define USB_RELAY_DEVICE_H__
3
c099d658 4#define USBRELAY_LIB_VER 0x02
5
8401c785 6#ifdef WIN32
c099d658 7#ifndef USBRL_CALL
8# define USBRL_CALL _cdecl
8401c785 9#endif
c099d658 10#ifndef USBRL_API
11# define USBRL_API __declspec(dllimport) USBRL_CALL
8401c785 12#endif
13#
14#else /* !WIN32 */
15#
c099d658 16#ifndef USBRL_CALL
17# define USBRL_CALL
8401c785 18#endif
c099d658 19#ifndef USBRL_API
20# define USBRL_API USBRL_CALL
8401c785 21#endif
22#
23#endif /* WIN32 */
24
25#include <stddef.h>
26
27enum usb_relay_device_type
28{
29 USB_RELAY_DEVICE_ONE_CHANNEL = 1,
30 USB_RELAY_DEVICE_TWO_CHANNEL = 2,
31 USB_RELAY_DEVICE_FOUR_CHANNEL = 4,
32 USB_RELAY_DEVICE_EIGHT_CHANNEL = 8
33};
34
35
36/** USB relay board info structure*/
37struct usb_relay_device_info
38{
c099d658 39 char *serial_number;
8401c785 40 char *device_path;
c099d658 41 intptr_t /*enum usb_relay_device_type*/ type;
8401c785 42 struct usb_relay_device_info* next;
43};
44
c099d658 45typedef struct usb_relay_device_info *pusb_relay_device_info_t;
46
8401c785 47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/** Initialize the USB Relay Library
52@returns: This function returns 0 on success and -1 on error.
53*/
c099d658 54int USBRL_API usb_relay_init(void);
8401c785 55
56/** Finalize the USB Relay Library.
57This function frees all of the static data associated with USB Relay Library.
58It should be called at the end of execution to avoid memory leaks.
59@returns:This function returns 0 on success and -1 on error.
60*/
c099d658 61int USBRL_API usb_relay_exit(void);
8401c785 62
63/** Enumerate the USB Relay Devices.*/
c099d658 64pusb_relay_device_info_t USBRL_API usb_relay_device_enumerate(void);
8401c785 65
66
67/** Free an enumeration Linked List*/
c099d658 68void USBRL_API usb_relay_device_free_enumerate(struct usb_relay_device_info*);
8401c785 69
70/** Open device that serial number is serial_number
71@return: This function returns a valid handle to the device on success or NULL on failure.
72e.g: usb_relay_device_open_with_serial_number("abcde", 5") */
c099d658 73intptr_t USBRL_API usb_relay_device_open_with_serial_number(const char *serial_number, unsigned len);
8401c785 74
75/* Open a USB relay device
76@return: This function returns a valid handle to the device on success or NULL on failure.
77*/
c099d658 78intptr_t USBRL_API usb_relay_device_open(struct usb_relay_device_info *device_info);
8401c785 79
80/* Close a USB relay device*/
c099d658 81void USBRL_API usb_relay_device_close(intptr_t hHandle);
8401c785 82
83/** Turn ON a relay channel on the USB-Relay-Device
84@param hHandle -- which usb relay device your want to operate
85@param index -- the channel number: 1...max
86@returns: 0 -- success; 1 -- error; 2 -- index is invalid
87*/
c099d658 88int USBRL_API usb_relay_device_open_one_relay_channel(intptr_t hHandle, int index);
8401c785 89
90/** Turn ON all relay channels on the USB-Relay-Device
91@param hHandle -- which usb relay device your want to operate
92@returns: 0 -- success; 1 -- error
93*/
c099d658 94int USBRL_API usb_relay_device_open_all_relay_channel(intptr_t hHandle);
8401c785 95
96/** Turn OFF a relay channel on the USB-Relay-Device
97@param index -- which channel your want to close
98@param hHandle -- which usb relay device your want to operate
99@returns: 0 -- success; 1 -- error
100*/
c099d658 101int USBRL_API usb_relay_device_close_one_relay_channel(intptr_t hHandle, int index);
8401c785 102
103/** Turn OFF all relay channels on the USB-Relay-Device
104@param hHandle -- which usb relay device your want to operate
105@returns: 0 -- success; 1 -- error; 2 -- index is invalid
106*/
c099d658 107int USBRL_API usb_relay_device_close_all_relay_channel(intptr_t hHandle);
8401c785 108
109/*
110Status bits: one bit indicate a relay status.
111bit 0/1/2/3/4/5/6/7/8 indicate channel 1/2/3/4/5/6/7/8 status
112Bit value 1 means ON, 0 means OFF.
113@returns: 0 -- success; 1 -- error
114*/
c099d658 115int USBRL_API usb_relay_device_get_status(intptr_t hHandle, unsigned int *status);
8401c785 116
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif /* USB_RELAY_DEVICE_H__ */