How would I reproduce the functionality of the Windows winusb driver on Linux? Do I even need to?

796 Views Asked by At

I need to implement an application on Linux that drives a USB connected device (a medical instrument). The application will be written in C++ (2011 standard).

The current application is written for Windows 10 in C# and uses the standard Winusb driver enumerated for the device. I have a complete protocol specification for the commands and the events/interrupts coming back. Unfortunately, I'm not sure how I can pass these to the USB layer in Linux. If it was a simple serial device, there would be no problem but I'm guessing the command responses and the interrupt events are multiplexed by the driver using the functionality in the Winusb driver.

Where's the best place to start in terms of documentation? Alternatively, is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?

Any help appreciated. Thanks

2

There are 2 best solutions below

1
Khoyo On BEST ANSWER

Alternatively, is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?

One way is using directly the generic kernel API for USB (see the Asynchronous I/O parts to get the interrupts):

https://www.kernel.org/doc/html/v4.15/driver-api/usb/usb.html

This is the strict Linux equivalent of WinUSB.

The potentially less hard way is using libusb, which also get you cross-platform features.

(I am assuming your device is recognized correctly by the kernel, and doesn't need a custom driver)

0
David Grayson On

Is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?

Yes. libusb is a popular USB abstraction library that supports Linux, macOS, and Windows. I also wrote a similar library called libusbp with a different set of features that were more useful for my applications. These are C libraries so it will take some work to interoperate with them from C#, but once you do that, you can probably use the same code on either Windows or Linux (so you wouldn't have to maintain your code for calling WinUSB).