Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Powerful Human Interface Devices Library For Delphi/C++ Builder FireMonkey Apps

Communicating with Human Interface Devices such as Alphanumeric display, Bar Code Reader, Sensors, Volume control on Speakers/Headsets becomes a primary use case for real-world, Cross-platform applications. Do you spend more time in building libraries to communicate with HID for your Delphi/C++ FireMonkey applications? WINSOFT Provides a powerful library to get the job done. It uses the standard Windows HID API.

Features:

  • Able to notify on HID Device arrival and removal.
  • Can retrieve all the HID devices information available in the System.
  • Flexible to getting/set Feature Report for the HID devices.
  • Works with Windows 32/64-bit applications.

Versions Supported: Delphi/C++ Builder XE2 – Delphi 10.4.

Platforms: Windows, OS X, Android, and iOS;

Steps to Download and use the Native HID Library:

  1. Download Native HID for FireMonkey and Unzip the file.
  2. Nahttps://winsoft.sk/nathid.htmvigate to the Library folder for different Versions. e.g) Delphi104-Win32.
  3. Read the Readme.txt file to know about features and copyright information.
  4. Create a Windows VCL Application and use FHid.pas in the uses section.
  5. Include the Library folder into Project->Options->Delphi Compiler->Search Path.
  6. Compile and check for using the library.

NativeHID Download and Use for FireMonkey demo:

Key HID concepts:
Report -Reports are the actual data that is exchanged between a device and a software client.

Report Descriptor – The Report Descriptor describes the format and meaning of the data that the device supports.
UsageTables – Contain a list with descriptions of Usages, which describe the intended meaning and use of a particular item described in the Report Descriptor. For example, a Usage is defined for the left button of a mouse.  USB-IF WorkGroup Publishes the Usage Tables. See USB-IF HID Specifications.

How to build FireMonkey applications using Native HID library:

1. Open Rad Studio 10.4 and Create a Blank Multi Device Application, use FHid.pas in the uses section.
2. Include the Library folder into Project->Options->Delphi Compiler->Search Path.

3. Create a Device instance and open,

Device := TFHidDevice.Create; // Creates an Instance of TFHidDevice
Device.Open // Open the HID Device

4. ShowDeviceProperties.

with Device do
  try
    AddLine('Vendor ID: ' + IntToHex(VendorID, 4));
    AddLine('Product ID: ' + IntToHex(ProductID, 4));
    AddLine('Version number: ' + IntToHex(VersionNumber, 4));
    AddLine('Serial number: ' + SerialNumber);
    AddLine('Manufacturer: ' + Manufacturer);
    AddLine('Product: ' + Product);
    AddLine('Usage page: ' + IntToStr(UsagePage));
    AddLine('Usage: ' + IntToStr(Usage));
    AddLine('Input report length: ' + IntToStr(InputReportLength));
    AddLine('Output report length: ' + IntToStr(OutputReportLength));
    AddLine('Feature report length: ' + IntToStr(FeatureReportLength));
    AddLine('Input buffer count: ' + IntToStr(InputBufferCount));
    for I := 1 to 255 do
      if HasString[I] then
        AddLine('String ' + IntToStr(I) + ': ' + Strings[I])
      else
        Break;
  except
    on E: Exception do
      AddLine('Exception: ' + E.Message);
  end;

5. Get Device Names,

var   DeviceNames : TWStringDynArray; begin   With Device do     DeviceNames := Enumerate; end;

6. For each DeviceNames GetFeatureReport, GetInputReport and Read data by reopening the device in Read-only,

with Device do
  // Feature Report
  if FeatureReportSupported then
    for J := 0 to 9 do
      try
        AddLine('Feature report ' + IntToStr(J) + ': ' + ByteArrayToString(GetFeatureReport(J)));
      except
      on E: Exception do
        AddLine('Feature report ' + IntToStr(J) + ' exception: ' + E.Message);
      end;
   // Input Report   
   if InputReportSupported then
     for J := 0 to 9 do
       try
         AddLine('Input report ' + IntToStr(J) + ': ' + ByteArrayToString(GetInputReport(J)));
       except
       on E: Exception do
         AddLine('Input report ' + IntToStr(J) + ' exception: ' + E.Message);
       end;
   // Open Device read only
   if ReadSupported then
   begin
     // reopen device with read access
     Open(DeviceNames[I], True, False);
       for J := 0 to 9 do
         try
           AddLine('Read: ' + ByteArrayToString(Read(300)));
         except
         on E: Exception do
           AddLine('Read exception: ' + E.Message);
         end;
    end;

7. Close the Device.

Device.close // Close the HID Device.

Native HID Library for FireMonkey Code demo :

Conclusion:  It’s quite easy to interact with HID in your FireMonkey applications. WINSOFT saved our time in nailing the Windows HID API and help us to build quickly using NativeHID Library.  

Head over and check out the full WINSOFT Native HID Library for Access in Delphi and C++Builder.

Exit mobile version