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  https://github.com/libusb/hidapi .
21 ********************************************************/
22 
27 #ifndef HIDAPI_H__
28 #define HIDAPI_H__
29 
30 #include <wchar.h>
31 
32 #ifdef _WIN32
33  #define HID_API_EXPORT __declspec(dllexport)
34  #define HID_API_CALL
35 #else
36  #define HID_API_EXPORT
37  #define HID_API_CALL
38 #endif
39 
40 #define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL
46 #define HID_API_VERSION_MAJOR 0
47 
51 #define HID_API_VERSION_MINOR 10
52 
56 #define HID_API_VERSION_PATCH 1
57 
58 /* Helper macros */
59 #define HID_API_AS_STR_IMPL(x) #x
60 #define HID_API_AS_STR(x) HID_API_AS_STR_IMPL(x)
61 #define HID_API_TO_VERSION_STR(v1, v2, v3) HID_API_AS_STR(v1.v2.v3)
62 
67 #define HID_API_VERSION_STR HID_API_TO_VERSION_STR(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH)
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72  struct hid_api_version {
73  int major;
74  int minor;
75  int patch;
76  };
77 
78  struct hid_device_;
79  typedef struct hid_device_ hid_device;
82  struct hid_device_info {
84  char *path;
86  unsigned short vendor_id;
88  unsigned short product_id;
90  wchar_t *serial_number;
93  unsigned short release_number;
97  wchar_t *product_string;
100  unsigned short usage_page;
103  unsigned short usage;
113 
116  };
117 
118 
134 
147 
169  struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
170 
180 
199  HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
200 
217 
246  int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length);
247 
269  int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
270 
291  int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length);
292 
312 
341  int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length);
342 
368  int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length);
369 
393  int HID_API_EXPORT HID_API_CALL hid_get_input_report(hid_device *dev, unsigned char *data, size_t length);
394 
403 
414  int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen);
415 
426  int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen);
427 
438  int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen);
439 
451  int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen);
452 
472  HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
473 
482 
483 
491  HID_API_EXPORT const char* HID_API_CALL hid_version_str(void);
492 
493 #ifdef __cplusplus
494 }
495 #endif
496 
497 #endif
498 
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...
int interface_number
Definition: hidapi.h:112
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
Get The Product String from a HID device.
Definition: hidapi.h:82
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonblock)
Set the device handle to be non-blocking.
#define HID_API_EXPORT
Definition: hidapi.h:36
HID_API_EXPORT const struct hid_api_version *HID_API_CALL hid_version(void)
Get a runtime version of the library.
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
wchar_t * manufacturer_string
Definition: hidapi.h:95
char * path
Definition: hidapi.h:84
int HID_API_EXPORT HID_API_CALL hid_get_input_report(hid_device *dev, unsigned char *data, size_t length)
Get a input report from a HID device.
int HID_API_EXPORT HID_API_CALL hid_exit(void)
Finalize the HIDAPI library.
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
Send a Feature report to the device.
struct hid_device_info * next
Definition: hidapi.h:115
Definition: hidapi.h:72
unsigned short product_id
Definition: hidapi.h:88
HID_API_EXPORT hid_device *HID_API_CALL hid_open_path(const char *path)
Open a HID device by its path name.
wchar_t * serial_number
Definition: hidapi.h:90
unsigned short vendor_id
Definition: hidapi.h:86
struct hid_device_info HID_API_EXPORT *HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen)
Get The Manufacturer String from a HID device.
wchar_t * product_string
Definition: hidapi.h:97
int HID_API_EXPORT HID_API_CALL hid_init(void)
Initialize the HIDAPI library.
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.
unsigned short usage
Definition: hidapi.h:103
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
HID_API_EXPORT const char *HID_API_CALL hid_version_str(void)
Get a runtime version string of the library.
struct hid_device_ hid_device
Definition: hidapi.h:79
#define HID_API_EXPORT_CALL
Definition: hidapi.h:40
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
Get a feature report from a HID device.
unsigned short usage_page
Definition: hidapi.h:100
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
Get a string from a HID device, based on its string index.
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs)
Free an enumeration Linked List.
#define HID_API_CALL
Definition: hidapi.h:37
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev)
Close a HID device.
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen)
Get The Serial Number String from a HID device.
unsigned short release_number
Definition: hidapi.h:93
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *dev)
Get a string describing the last error which occurred.