Skip to main content

HidDevice Class

Package: GHIElectronics.Endpoint.Devices.UsbHost
Namespace: GHIElectronics.Endpoint.Devices.UsbHost

A HID device that is no keyboard, mouse or joystick (a sensor, a USB I/O board, a UPS...): its reports, as hidapi gives them.

public class HidDevice : BaseDevice

Remarks​

Open it with the DeviceName of a HID device from UsbHostController ("/dev/hidraw0"). A report's first byte is its report ID: 0 for a device that does not number its reports.

Constructors​

HidDevice(string deviceName)​

public HidDevice(string deviceName)

Opens the HID device that UsbHostController reported ("/dev/hidraw0").

Properties​

ProductName​

public string ProductName { get; }

The device's name ("Microchip Technology Inc. MCP2221 USB-I2C/UART Combo")

Returns string

Methods​

GetFeatureReport(Span<byte> buffer)​

public int GetFeatureReport(Span<byte> buffer)

Gets a feature report. buffer[0] is the report ID (0 if the device has none).

Returns int: The report's length, with its report ID.

GetReportDescriptor()​

public byte[] GetReportDescriptor()

The report descriptor: what reports the device has and what is in them.

Returns byte[]

Read(Span<byte> buffer, int timeout)​

public int Read(Span<byte> buffer, int timeout)

Reads an input report (its first byte is its report ID if the device numbers its reports).

ParameterTypeDescription
bufferSpan<byte>Where the report goes.
timeoutintHow long to wait for one, in milliseconds (Timeout.Infinite: as long as it takes).

Returns int: The report's length, 0 if none came in time.

SendFeatureReport(ReadOnlySpan<byte> report)​

public void SendFeatureReport(ReadOnlySpan<byte> report)

Sends a feature report. Its first byte is the report ID (0 if the device has none).

Write(ReadOnlySpan<byte> report)​

public int Write(ReadOnlySpan<byte> report)

Sends an output report. Its first byte is the report ID (0 if the device has none).

Returns int: The number of bytes written.