HID for FireMonkey 1.0 XE2 - 10.1 Full Source » Developer.Team

HID for FireMonkey 1.0 XE2 - 10.1 Full Source

HID for FireMonkey 1.0 XE2 - 10.1 Full Source
HID for FireMonkey 1.0 XE2 - 10.1 Full Source | 1 Mb


Delphi and C++ Builder library for communicating with HID USB devices.

Features

Uses HIDAPI library
Supports Windows 32, Windows 64 and OS X
Available for Delphi/C++ XE2 - 10.1
Source code included in full version
Royalty free distribution in applications

Unit

Winsoft.FireMonkey.Hid

Class

type TFHid = class

Represents HID device.

Variables

var LibraryName: string = {$ifdef MACOS} 'hidapi.dylib'; {$else} 'hidapi.dll'; {$endif MACOS}

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: string; // read only

Returns the manufacturer string from a HID device.

property ProductName: string; // read only

Returns the product string from a HID device.

property SerialNumber: string; // read only

Returns the serial number string from a HID device.

property Strings[Index: Integer]: string; // 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): TFHidDevices;

type TFHidDevices = array of TFHidDevice;

type TFHidDevice = record
  DevicePath: string;
  Vendor: Word;
  Product: Word;
  ReleaseNumber: Word;
  SerialNumber: string;
  Manufacturer: string;
  ProductName: string;
  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(Data: 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: string;

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

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

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: string);

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

function Read(Data: 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(Data: 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(Data: 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(Data: 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(Data: 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(Data: 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: TFDeviceArrivalEvent;

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

Occurs when USB device is attached.

property OnDeviceRemoved: TFDeviceRemovedEvent;

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

Occurs when USB device is detached .


[/b]

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