static void Main() { _device = HidDevices.Enumerate(VendorId, ProductId).FirstOrDefault(); if (_device != null) { _device.OpenDevice(); _device.Inserted += DeviceAttachedHandler; _device.Removed += DeviceRemovedHandler; _device.MonitorDeviceEvents = true; _device.ReadReport(OnReport); Console.WriteLine("Reader found, press any key to exit."); Console.ReadKey(); _device.CloseDevice(); } else { Console.WriteLine("Could not find reader."); Console.ReadKey(); } }
static void Main() { foreach (var productId in ProductIds) { _device = HidDevices.Enumerate(VendorId, productId).FirstOrDefault(); if (_device == null) continue; _currentProductId = productId; _device.OpenDevice(); _device.Inserted += DeviceAttachedHandler; _device.Removed += DeviceRemovedHandler; _device.MonitorDeviceEvents = true; _device.ReadReport(OnReport); break; } if (_device != null) { Console.WriteLine("Gamepad found, press any key to exit."); Console.ReadKey(); _device.CloseDevice(); } else { Console.WriteLine("Could not find a gamepad."); Console.ReadKey(); } }