Skip to content
Oleksandr Hubanov edited this page Jun 12, 2020 · 4 revisions

This code demonstrates how to use the Hid Library with an HHP IT4600 Scanner.

using HidLibrary;
using System.Diagnostics;
using System.Threading;

...

HIDLibrary.HidDevice[] HidDeviceList;
HidDevice HidDevice;

// Enumerate the devices with the Vendor Id
// and Product Id of the IT4600
HidDeviceList = HidDevices.Enumerate(0x0536, 0x0207);

if (HidDeviceList.Length > 0) {

    // Grab the first device
    HidDevice = HidDeviceList[0];

    // Check if connected...
    Debug.WriteLine("Connected: " + HidDevice.IsConnected.ToString());
    byte[] OutData = new byte[HidDevice.Capabilities.OutputReportByteLength - 1];

    // Send a report to initiate an error sound
    OutData[0] = 0x04;
    OutData[1] = 0x020;

    HidDevice.Write(OutData);

    // Send a report to initiate an success sound
    OutData[1] = 0x040;

    HidDevice.Write(OutData);

    // Send a report to start a scan
    OutData[1] = 0x04;
    HidDevice.Write(OutData);
    Thread.Sleep(2000);

    // Send a report to stop the scan
    OutData[1] = 0x01;
    HidDevice.Write(OutData);

    // Blocking read of report
    HidDeviceData InData;
    string Text;

    InData = HidDevice.Read();
    Text = System.Text.ASCIIEncoding.ASCII.GetString(InData.Data);

    Debug.WriteLine(Text);
}

Jan Axelson's USB Hid Programming Page: Excellent resource for USB Hid development. Full code samples in a number of different languages demonstrate how to use the Windows setup and Hid API.
Jan Axelson's 'USB Complete': Jan Axelson’s guide to USB programming. Very good coverage of Hid. Must read for anyone new to Hid programming.

Clone this wiki locally