1 How to use USB_RELAY_DEVICE DLL
2 ===============================
6 Changes to the original DLL:
7 ----------------------------
8 - The type used for handles changed from int to intptr_t, for 64-bit compatibility.
9 This should be binary compatible with existing 32-bit clients.
10 - Added helper functions for use from managed languages and scripts; see below, and
11 `usb_relay_device_lib_version`
18 Call this before calling other functions
20 * `usb_relay_device_enumerate`
21 Enumerates all Relay devices plugged into the PC.
22 Returns list of usb_relay_device_info structures.
23 Caller should free this list by passing it to usb_relay_device_free_enumerate().
25 * `usb_relay_device_open`
26 Opens one Relay board device by its usb_relay_device_info structure,
27 obtained from usb_relay_device_enumerate().
29 * `usb_relay_device_open_with_serial_number`
30 Opens one Relay board device by its serial number string.
31 These strings can be obtained from usb_relay_device_enumerate().
33 * `usb_relay_device_open_one_relay_channel`
34 Turns ON one channel of a Relay board.
36 - device handle, obtained from usb_relay_device_open()
37 - Index: integer from 1 to the maximal number of channels on a board.
39 * `usb_relay_device_open_all_relay_channel`
40 Turns ON all channels on a board.
42 * `usb_relay_device_close_one_relay_channel`
43 Turns OFF one channel of a Relay board.
45 - device handle, obtained from `usb_relay_device_open()`
46 - Index: integer from 1 to the maximal number of channels on a board.
48 * `usb_relay_device_close_all_relay_channel`
49 Turns OFF all channels on a board.
51 * `usb_relay_device_get_status`
52 Get status of all channels on a board as a bit mask.
53 The least significant bit in returned value corresponds to channel 1.
54 Bit value 1 means the corresponding relay is switched ON, value 0 means the relay is OFF.
56 * `usb_relay_device_close`
57 Closes the Relay device handle opened by `usb_relay_device_open()` or
58 `usb_relay_device_open_with_serial_number()`
63 * `usb_relay_device_lib_version`
64 Returns the version of the library.
65 The lower 16 bits are the library version. Higher bits: undefined, ignore.
66 Note: this function is extension of the original library.
70 Helper functions for managed callers and scripts
71 ------------------------------------------------
73 The following functions help to use this lib in managed languages by avoiding dereferencing C pointers.
74 Native C or C++ callers do not have to use these.
75 All these functions are extension of the original library.
76 The `ptr_usb_relay_device_info parameter` is pointer to `struct usb_relay_device_info`, converted to a pointer-sized integer.
77 Type `int` means the "C" integer (which usually is 32-bit), `ptr` is a pointer-sized integer.
79 * `ptr_usb_relay_device_info usb_relay_device_next_dev(ptr_usb_relay_device_info)`
80 Returns pointer to the next element of device list obtained from `usb_relay_device_enumerate`
82 * `int usb_relay_device_get_num_relays(ptr_usb_relay_device_info)`
83 Returns number of relay channels on the device. Values <= 0 are not valid and mean error.
85 * `ptr usb_relay_device_get_id_string(ptr_usb_relay_device_info)`
86 Returns the "serial number" string of the device, as pointer to constant C string (one-byte characters, null terminated).
88 * `int usb_relay_device_get_status_bitmap(intptr_t hHandle)`
89 Returns the states of all channels on a relay device as a bit mask.
90 This is same as `usb_relay_device_get_status` but without dereferencing pointers.
91 Negative returned values indicate error. Else, bits 0-7 of the value are states of each channel.
96 If error occurred, the API functions that return error code return -1;
97 functions that return handles or pointers return NULL.
98 Application is responsible to check the returned value.
102 * The library does not detect hot plug/unplug of USB devices.
103 * The library is not thread-safe. Client application must ensure that
104 only one thread calls the library.
106 Windows, Visual C++ applications
107 ---------------------------------
109 Include file name: `usb_relay_device.h`
110 Library file name: `usb_relay_device.lib`
112 Put the following lines in your source file:
114 `#include <usb_relay_device.h>`
116 `#pragma comment(lib, "usb_relay_device.lib")`
118 The library can be also loaded dynamically.
119 The file `usb_relay_device.dll` must be installed with your application.
120 Use either 32-bit or 64-bit DLL, matching your application.
121 The DLL may require VC++ redistributable runtime library.
124 Linux C/C++ applications (gcc, llvm)
126 Same as above, except the #pragma. The library name is `usb_relay_device.so`.
130 Python programs can use this library via the Ctypes module. Examples are in Test directory.
131 Be sure to use the correct variant (32 or 64-bit) for your Python interpreter.
133 Managed .NET applications (C#, VB.NET, Powershell)
134 ---------------------------------------
135 Managed programs can use this library via PInvoke.
136 Be sure to use the correct variant (32 or 64-bit).
139 GCC or MinGW applications on Windows
140 ------------------------------------