hidapi
hidapi.h
Go to the documentation of this file.
1 /*******************************************************
2  HIDAPI - Multi-Platform library for
3  communication with HID devices.
4 
5  Alan Ott
6  Signal 11 Software
7 
8  8/22/2009
9 
10  Copyright 2009, All Rights Reserved.
11 
12  At the discretion of the user of this library,
13  this software may be licensed under the terms of the
14  GNU General Public License v3, a BSD-Style license, or the
15  original HIDAPI license as outlined in the LICENSE.txt,
16  LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
17  files located at the root of the source distribution.
18  These files may also be found in the public source
19  code repository located at:
20  http://github.com/signal11/hidapi .
21 ********************************************************/
22 
27 #ifndef HIDAPI_H__
28 #define HIDAPI_H__
29 
30 #include <wchar.h>
31 
32 #ifdef _WIN32
33 
36 #ifdef USE_EXPORT_DLL
37  #define HID_API_EXPORT __declspec(dllexport)
38 #else
39 #define HID_API_EXPORT
40 #endif
41 
42 #define HID_API_CALL
44 #else
45  #define HID_API_EXPORT
46  #define HID_API_CALL
47 #endif
48 
49 #define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54  struct hid_device_;
55  typedef struct hid_device_ hid_device;
58  struct hid_device_info {
60  char *path;
62  unsigned short vendor_id;
64  unsigned short product_id;
66  wchar_t *serial_number;
69  unsigned short release_number;
73  wchar_t *product_string;
76  unsigned short usage_page;
79  unsigned short usage;
85 
88  };
89 
90 
106 
119 
141  struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
142 
152 
169  HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
170 
185 
212  int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);
213 
233  int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
234 
253  int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);
254 
273  int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);
274 
301  int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);
302 
326  int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);
327 
334 
345  int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);
346 
357  int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);
358 
369  int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);
370 
382  int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);
383 
393  HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);
394 
395 #ifdef __cplusplus
396 }
397 #endif
398 
399 #endif
400 
HID_API_EXPORT hid_device *HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number...
Definition: hid.c:696
int interface_number
The USB interface which this logical device represents.
Definition: hidapi.h:84
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen)
Get The Serial Number String from a HID device.
Definition: hid.c:1278
hidapi info structure
Definition: hidapi.h:58
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length)
Send a Feature report to the device.
Definition: hid.c:1174
#define HID_API_EXPORT
API export macro.
Definition: hidapi.h:45
wchar_t * manufacturer_string
Manufacturer String.
Definition: hidapi.h:71
char * path
Platform-specific device path.
Definition: hidapi.h:60
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device)
Close a HID device.
Definition: hid.c:1235
int HID_API_EXPORT HID_API_CALL hid_exit(void)
Finalize the HIDAPI library.
Definition: hid.c:511
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length)
Read an Input report from a HID device.
Definition: hid.c:1161
struct hid_device_info * next
Pointer to the next device.
Definition: hidapi.h:87
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen)
Get The Product String from a HID device.
Definition: hid.c:1273
Definition: hid.c:145
unsigned short product_id
Device Product ID.
Definition: hidapi.h:64
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length)
Get a feature report from a HID device.
Definition: hid.c:1204
HID_API_EXPORT hid_device *HID_API_CALL hid_open_path(const char *path)
Open a HID device by its path name.
Definition: hid.c:870
wchar_t * serial_number
Serial Number.
Definition: hidapi.h:66
unsigned short vendor_id
Device Vendor ID.
Definition: hidapi.h:62
struct hid_device_info HID_API_EXPORT *HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
Definition: hid.c:521
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *device)
Get a string describing the last error which occurred.
Definition: hid.c:1299
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen)
Get The Manufacturer String from a HID device.
Definition: hid.c:1268
wchar_t * product_string
Product string.
Definition: hidapi.h:73
int HID_API_EXPORT HID_API_CALL hid_init(void)
Initialize the HIDAPI library.
Definition: hid.c:493
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
Read an Input report from a HID device with timeout.
Definition: hid.c:1076
unsigned short usage
Usage for this Device/Interface (Windows/Mac only).
Definition: hidapi.h:79
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen)
Get a string from a HID device, based on its string index.
Definition: hid.c:1283
#define HID_API_EXPORT_CALL
API export and call macro.
Definition: hidapi.h:49
unsigned short usage_page
Usage Page for this Device/Interface (Windows/Mac only).
Definition: hidapi.h:76
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs)
Free an enumeration Linked List.
Definition: hid.c:682
#define HID_API_CALL
API call macro.
Definition: hidapi.h:46
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length)
Write an Output report to a HID device.
Definition: hid.c:1003
unsigned short release_number
Device Release Number in binary-coded decimal, also known as Device Version Number.
Definition: hidapi.h:69
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock)
Set the device handle to be non-blocking.
Definition: hid.c:1166