![Barcode For FMX | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/Barcode-For-FMX.jpg?resize=1024%2C694&ssl=1)
- Introduction
The Native HID library for Firemonkey is a library for communicating with Human Interface Devices. It uses Windows HID Api and supports both Windows 32 and Windows 64. A short video describes for to install the library in your Rad Studio.
2. Components in the Demo and what they do
The Demo contains only one Tbutton and TMemo component for the results in Text after onButton click execution. We first call the SetCursor procedure with chHourGlass type of Cursor. It is typically used to inform the user to wait until an application completes its current operation. Then using Enumerate all the device names are stored in a String Dynamic array. In the next short video you can see the Demo in action.
To show all the available devices a FOR cycle goes through the DeviceNames DynArray and adds the devices line by line. Depending on the Boolean properties different report is shown in the TMemo.
- FeatureReportSupported;
1 2 3 4 5 6 7 8 |
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; |
- InputReportSupported;
1 2 3 4 5 6 7 8 |
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; |
- ReadSupported
1 2 3 4 5 6 7 8 9 10 11 12 |
if ReadSupported then begin <em>// reopen device with read access</em> 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; |
Every device in the Dynamic array is listed with Product Id, Vendor Id, version number, serial number, etc which is in other words the main info of the certain device. All this information is executed in the ShowDeviceInfo procedure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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; |
There is also some code, executed on the FormShow event of the form. When OnDeviceArrival event of the device is called, it executes the code bellow:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
AddLine; AddLine('Device arrival: ' + DeviceName); try Device.Open(DeviceName, False, False); try ShowDeviceInfo; finally Device.Close end; except on E: Exception do AddLine('Exception: ' + E.Message); end; |
When OnDeviceRemoved event of the device is called, it executes the code bellow:
1 2 |
AddLine; AddLine('Device removed: ' + DeviceName); |
The ‘AddLine’ procedure itself checks if there is no text and lines in the TMemo. If both are true, the first line is skipped.
1 2 3 |
if (Text = '') and (Memo.Lines.Count = 0) then Exit; <em>// skip first empty lines</em> Memo.Lines.Add(Text); |
You can download the Demo from the link below:
https://winsoft.sk/fnathid.htm
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition