Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hid Test

Copyright © Bill Wang

All rights reserved.

Gui

Requirements

📦 NuGet Packages

📬 IDE

  • Visual Studio 2022
  • .net 6.0

🙌 Getting Started

Initialize Hid Device

MyHidClass myHidDevice;
myHidDevice = new MyHidClass(TestSetting.UsbVid, TestSetting.UsbPid);

Add USB Plug/Unplug Event

MyHidClass.localDeviceList.Changed += DeviceListChangedHandler;

// Deal with the USB plug & unplug
void DeviceListChangedHandler(object? sender, EventArgs e)
{        
    myHidDevice.CheckHidDevice();

    if (myHidDevice.hidDevice == null)
    {
        DeviceRemoved();
    }
    else
    {
        DeviceConnected();
    }
}

Add HID Input Report Callback

myHidDevice.InputReportReceived = InputReportReceived;

// Parse the HID Input Report
void InputReportReceived(byte[] bytes, int length)
{
    // Decode bytes
}

Check USB at startup

DeviceListChangedHandler(null, null); // Check USB

Complete Example

MyHidClass myHidDevice;
myHidDevice = new MyHidClass(TestSetting.UsbVid, TestSetting.UsbPid);
myHidDevice.InputReportReceived = InputReportReceived;
MyHidClass.localDeviceList.Changed += DeviceListChangedHandler;
DeviceListChangedHandler(null, null); // Check USB

// Parse the HID Input Report
void InputReportReceived(byte[] bytes, int length)
{
    // Decode bytes
}

// Deal with the USB plug & unplug
void DeviceListChangedHandler(object? sender, EventArgs e)
{        
    myHidDevice.CheckHidDevice();

    if (myHidDevice.hidDevice == null)
    {
        DeviceRemoved();
    }
    else
    {
        DeviceConnected();
    }
}

Write to HID

Send string to HID

public async Task WriteStringAsync(string command)

Send byte array to HID

async Task WriteBytesAsync(byte[] buffer, int timeout = 1)

References

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages