Winsoft HID Library v1.8 Delphi/C++ Builder 5 - 10.3 Rio Full Source

Winsoft HID Library v1.8 Delphi/C++ Builder 5 - 10.3 Rio Full Source

Winsoft HID Library v1.8 Delphi/C++ Builder 5 - 10.3 Rio Full Source
Winsoft HID Library v1.8 Delphi/C++ Builder 5 - 10.3 Rio Full Source


Delphi and C++ Builder library for communicating with HID USB devices.
uses HIDAPI library
supports Windows 32 and Windows 64
available for Delphi/C++ Builder 5 - 10.3 and Lazarus 1.8.4
source code included in registered version
royalty free distribution in applications

Unit

Hid

Class

type THid = class

Represents HID device.

Types

type {$ifdef D2009PLUS} WString = string; {$else} WString = WideString; {$endif D2009PLUS}

Wide string type.

Variables

var LibraryName: string = 'hidapi.dll';

Name of the HIDAPI shared library.

Properties

property Active: Boolean; // read only

Returns true if HID device is opened.

property HasString[Index: Integer]: Boolean; // read only

Returns true if HID device contains string with the specified string index.

property Manufacturer: WString; // read only

Returns the manufacturer string from a HID device.

property ProductName: WString; // read only

Returns the product string from a HID device.

property SerialNumber: WString; // read only

Returns the serial number string from a HID device.

property Strings[Index: Integer]: WString; // read only

Returns the string from a HID device with the specified string index. Exception is raised if the HID device doesn't contain the specified string.

Methods

procedure Close;

Closes a HID device.

function Enumerate(Vendor: Integer = 0; Product: Integer = 0): THidDevices;

type THidDevices = array of THidDevice;

type THidDevice = record
DevicePath: WString;
Vendor: Word;
Product: Word;
ReleaseNumber: Word;
SerialNumber: WString;
Manufacturer: WString;
ProductName: WString;
UsagePage: Word;
Usage: Word;
end;

Enumerates the HID Devices. If Vendor is set to 0 then any vendor matches. If Product is set to 0 then any product matches. If Vendor and Product are both set to 0, then all HID devices will be returned.

function GetFeatureReport(dаta: PByte; Size: Integer): Integer;

Gets a feature report from a HID device. Set the first byte of data to the Report ID of the report to be read. Upon return, the first byte will still contain the Report ID, and the report data will start in next byte.
Function returns the number of bytes read plus one for the report ID (which is still in the first byte), or -1 on error.

function GetFeatureReport(Report: Byte): TByteDynArray;

Gets a feature report from a HID device with the specified Report ID. Function returns the specified feature report with the Report ID in the first byte. Exception is raised on error.

function LastError: WString;

Returns a string describing the last error which occurred or empty string if none error has occurred.

procedure Open(Vendor, Product: Integer; const SerialNumber: WString = '');

Opens a HID device using a Vendor ID, Product ID and optionally a serial number. If SerialNnumber is empty string, the first device with the specified Vendor and Product is opened. Exception is raised on error.

procedure Open(const DevicePath: WString);

Opens a HID device by its path name. Exception is raised on error.

function Read(dаta: PByte; Size: Integer): Integer;

Reads an input report from a HID device. Input reports are returned to the host through the INTERRUPT IN endpoint. The first byte will contain the report number if the device uses numbered reports.
Function returns the actual number of bytes read and -1 on error. If no packet was available to be read and the handle is in non-blocking mode, this function returns 0.

function Read: TByteDynArray;

Reads an input report from a HID device. Input reports are returned to the host through the INTERRUPT IN endpoint. The first byte will contain the report number if the device uses numbered reports.
If no packet was available to be read and the handle is in non-blocking mode, this function returns empty data. Exception is raised on error.

function Read(dаta: PByte; Size, Timeout: Integer): Integer;

Reads an input report from a HID device with timeout. Input reports are returned to the host through the INTERRUPT IN endpoint. The first byte will contain the report number if the device uses numbered reports.
Timeout parameter is timeout in milliseconds or -1 for blocking wait.
Function returns the actual number of bytes read and -1 on error. If no packet was available to be read within the timeout period, this function returns 0.

function Read(Timeout: Integer): TByteDynArray;

Reads an input report from a HID device with timeout. Input reports are returned to the host through the INTERRUPT IN endpoint. The first byte will contain the report number if the device uses numbered reports.
Timeout parameter is timeout in milliseconds or -1 for blocking wait.
If no packet was available to be read within the timeout period, this function returns empty data. Exception is raised on error.

function SendFeatureReport(dаta: PByte; Size: Integer): Integer;

Sends a feature report to the device. Feature reports are sent over the Control endpoint as a Set_Report transfer. The first byte of data must contain the Report ID. For devices which only support a single report, this must be set to 0. The remaining bytes contain the report data.
Function returns the actual number of bytes written and -1 on error.

function SendFeatureReport(dаta: TByteDynArray): Integer;

Sends a feature report to the device. Feature reports are sent over the Control endpoint as a Set_Report transfer. The first byte of data must contain the Report ID. For devices which only support a single report, this must be set to 0. The remaining bytes contain the report data.
Function returns the actual number of bytes written. Exception is raised on error.

procedure SetBlockingMode(Blocking: Boolean);

Sets the HID device handle to blocking or non-blocking mode. In non-blocking mode calls to Read will return immediately with a value of 0 (or empty data) if there is no data to be read. In blocking mode, Read will wait (block) until there is data to read before returning.

function Write(dаta: PByte; Size: Integer): Integer;

Writes an output report to a HID device. The first byte of data must contain the Report ID. For devices which only support a single report, this must be set to 0. The remaining bytes contain the report data.
Write function will send the data on the first OUT endpoint, if one exists. If it does not, it will send the data through the Control Endpoint (Endpoint 0).
Function returns the actual number of bytes written and -1 on error.

function Write(dаta: TByteDynArray): Integer;

Writes an output report to a HID device. The first byte of data must contain the Report ID. For devices which only support a single report, this must be set to 0. The remaining bytes contain the report data.
Write function will send the data on the first OUT endpoint, if one exists. If it does not, it will send the data through the Control Endpoint (Endpoint 0).
Function returns the actual number of bytes written. Exception is raised on error.

Events

property OnDeviceArrival: TDeviceArrivalEvent;

type TDeviceArrivalEvent = procedure (Sender: TObject; const DeviceName: string) of object;

Occurs when USB device is attached.


property OnDeviceRemoved: TDeviceRemovedEvent;

type TDeviceRemovedEvent = procedure (Sender: TObject; const DeviceName: string) of object;

Occurs when USB device is detached .




Only for V.I.P
Warning! You are not allowed to view this text.


Information
Users of Guests are not allowed to comment this publication.