LibUsbDotNet doesn't open device

2.4k views Asked by At

I use latest LibUsbDotNet nuget package in Visual Studio 2017 on Win 10. For my full speed USB device with 2 interrupt endpoints and 1 bulk IN endpoint I installed WinUSB driver using zadiq 2.4 utility.

LibUsbDotNet can see my device when UsbDevice.AllDevices is called.

However, it can't open my device using:

UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(VID, PID);
UsbDevice MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

MyUsbDevice is null, no exception thrown.

I also tried to install different drivers (libusbk and libusb-win32), with no success.

Some time ago I coded an C++ app to communicate with my USB device using libusb library - and it works since then without any issue.

Is there anyone who can confirm that libusbdotnet is working product? I welcome any advice how to find what is wrong. Thanks.

2

There are 2 answers

0
Jaroslav Bán On

This is a bug in UsbDeviceFinder, where int.MaxValue is used instead of null to ignore a value. This makes UsbDeviceFinder unusable and all examples that use it don't work.

The workaround is to use

MyUsbDevice = context.Find(device => device.ProductId == ProductId && device.VendorId == VendorId);

instead of

MyUsbDevice = context.Find(MyUsbFinder);

0
BachPhi On

First find your vendor id & product id by using device manager, input device , details then Hardware ID.

Next, You need to download LibUsbDotNet_Setup.2.2.8.exe and run setup. During setup you should enable filter and choose your input device per your vendor id. Then your code will find the device afterwards