Copyright © Bill Wang
All rights reserved.
- Visual Studio 2022
- .net 6.0
MyHidClass myHidDevice;
myHidDevice = new MyHidClass(TestSetting.UsbVid, TestSetting.UsbPid);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();
}
}myHidDevice.InputReportReceived = InputReportReceived;
// Parse the HID Input Report
void InputReportReceived(byte[] bytes, int length)
{
// Decode bytes
}DeviceListChangedHandler(null, null); // Check USBMyHidClass 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();
}
}public async Task WriteStringAsync(string command)async Task WriteBytesAsync(byte[] buffer, int timeout = 1)