|
|
|
@ -7,10 +7,10 @@ namespace UsbHidTestApp; |
|
|
|
|
|
|
|
|
|
|
|
internal class Program |
|
|
|
internal class Program |
|
|
|
{ |
|
|
|
{ |
|
|
|
private static HidDevice _device; |
|
|
|
private static HidDevice? _device; |
|
|
|
private static bool _continue; |
|
|
|
private static bool _continue; |
|
|
|
private static Thread readThread; |
|
|
|
private static Thread? readThread; |
|
|
|
private static List<HidDevice> lastDevices; |
|
|
|
private static List<HidDevice>? lastDevices; |
|
|
|
private static StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; |
|
|
|
private static StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -89,6 +89,7 @@ internal class Program |
|
|
|
|
|
|
|
|
|
|
|
_device.OpenDevice(); |
|
|
|
_device.OpenDevice(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_device.Inserted += DeviceAttachedHandler; |
|
|
|
_device.Inserted += DeviceAttachedHandler; |
|
|
|
_device.Removed += DeviceRemovedHandler; |
|
|
|
_device.Removed += DeviceRemovedHandler; |
|
|
|
|
|
|
|
|
|
|
|
@ -151,7 +152,7 @@ internal class Program |
|
|
|
private static void DeviceAttachedHandler() |
|
|
|
private static void DeviceAttachedHandler() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Console.WriteLine("Device attached."); |
|
|
|
Console.WriteLine("Device attached."); |
|
|
|
_device.ReadReport(OnReport); |
|
|
|
_device?.ReadReport(OnReport); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void OnReport(HidReport report) |
|
|
|
private static void OnReport(HidReport report) |
|
|
|
@ -171,7 +172,7 @@ internal class Program |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
var readData = _device.Read(100); |
|
|
|
var readData = _device?.Read(100); |
|
|
|
|
|
|
|
|
|
|
|
if (readData != null) |
|
|
|
if (readData != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|