API

List devices

hid.enumerate()

Return a list of discovered HID devices.

The fields of dict are:

  • ‘path’

  • ‘vendor_id’

  • ‘product_id’

  • ‘serial_number’

  • ‘release_number’

  • ‘manufacturer_string’

  • ‘product_string’

  • ‘usage_page’

  • ‘usage’

  • ‘interface_number’

Parameters
  • vendor_id (int, optional) – Vendor id to look for, default = 0

  • product_id (int, optional) – Product id to look for, default = 0

Returns

List of device dictionaries

Return type

List[Dict]

Device class

class hid.device

Device class.

A device instance can be used to read from and write to a HID device.

close()

Close connection.

This should always be called after opening a connection.

error()

Get error from device.

Returns

Return type

str

Raises
  • ValueError – If connection is not opened.

  • IOError

get_feature_report()

Receive feature report.

Parameters
  • report_num (int) –

  • max_length (int) –

Returns

Incoming feature report

Return type

List[int]

Raises
  • ValueError – If connection is not opened.

  • IOError

get_indexed_string()

Return indexed string.

Returns

Return type

str

Raises
  • ValueError – If connection is not opened.

  • IOError

get_input_report()

Get input report

Parameters
  • report_num (int) –

  • max_length (int) –

Returns

Return type

List[int]

Raises
  • ValueError – If connection is not opened.

  • IOError

get_manufacturer_string()

Return manufacturer string (e.g. vendor name).

Returns

Return type

str

Raises
  • ValueError – If connection is not opened.

  • IOError

get_product_string()

Return product string (e.g. device description).

Returns

Return type

str

Raises
  • ValueError – If connection is not opened.

  • IOError

get_serial_number_string()

Return serial number.

Returns

Return type

str

Raises
  • ValueError – If connection is not opened.

  • IOError

open()

Open the connection.

Parameters
  • vendor_id (int, optional) – Vendor id to connect to, default = 0

  • product_id (int, optional) – Product id to connect to, default = 0

  • serial_number (unicode, optional) –

Raises

IOError

open_path()

Open connection by path.

Parameters

path (bytes) – Path to device

Raises

IOError

read()

Return a list of integers (0-255) from the device up to max_length bytes.

Parameters
  • max_length (int) – Maximum number of bytes to read

  • timeout_ms (int, optional) – Number of milliseconds until timeout (default: no timeout)

Returns

Read bytes

Return type

List[int]

send_feature_report()

Accept a list of integers (0-255) and send them to the device.

Parameters

buff (any) – Data to send (must be convertible into bytes)

Returns

Send result

Return type

int

set_nonblocking()

Set the nonblocking flag.

Parameters

v (int, bool) – Flag value (1 or 0, True or False)

Returns

Flag result

Return type

int

write()

Accept a list of integers (0-255) and send them to the device.

Parameters

buff (Any) – Data to write (must be convertible to bytes)

Returns

Write result

Return type

int