How to emulate USB devices?
Asked Answered
A

2

44

The rest of my team will make for my application a simple non-standard USB microphone, but until they finish it I will have to emulate it, for integration testing purposes.

  1. Is there any risk in a physical loopback? Yes there is
  2. Will a physical loopback work? Only with a USB bridge
  3. There is any way to create a logical loopback? (MSDN has something about this)
  4. There is any general purpose USB emulator software?

In case there is many options available I'd rather work it .NET/Matlab/Python solutions.

Acerate answered 16/12, 2009 at 11:11 Comment(1)
+1 for the discarding-methodology and well-structured question ;)Christinchristina
H
21

Edit: Proof of concept here

I strongly recommend this project, USB IP. It is a way of connecting USB devices over the network. There is a Windows client.

What this means is, you install the client on your Windows computer. This device then expects to talk to a USB device connected to a Linux computer, the server: diagram over how a USB IP client connects to a USB IP server

What you now do, is either create a fake device driver for Linux, that looks like is connected to a physical USB device, but in reality is just logic pretending to be your USB device. There are tutorials for writing USB drivers for Linux. Or you create your own stub driver for the Device Control Manager (see picture above). This stub driver could run on Windows or Linux, it wouldn't matter. It could even run on the same Windows machine which is the USB client.

The DSF USB Loopback Device mentioned in the question itself, would be the same kind of solution as a stub driver for the Device Control Manager, but taking Linux out of the picture altogether.

Hendrix answered 16/12, 2009 at 11:34 Comment(5)
Just wanted to add a note : DSF has been deprecated -- msdn.microsoft.com/en-us/library/windows/hardware/br259131.aspxLetti
strangely there doesn't seem to be a replacement. Do you have any pointers on where to look ? I need to write a USB device simulator on windows and currently all I have are dead-ends.Letti
I would look at the source of the USB IP Windows client itself. It manages to appear as any kind of USB device, so you should be able to modify it. Or create a stub driver as suggested in the answer itself. Possibly tedious and a little hard, but far from impossible. @LettiHendrix
You could use the USB IP project to emulate USB devices, as I demonstrated in this example. You install the USB IP driver on your PC, the driver listens to requests, and the python client send fake requests to emulate the device. In this example I demonstrated HID mouse device, but you can emulate any USB device. Important note: its just a POC, not a stable code!Mythopoeic
Cool example, @YaronShani.Hendrix
M
4

You can write virtual USB device using QEMU. You can duplicate already existing device, like the dev-serial.c found in this QEMU repository and change it for your needs.
After you write and compile your USB device you can simply attach it to your VM using the QEMU command line interface.

Mythopoeic answered 22/8, 2014 at 23:7 Comment(2)
Really? How to duplicate USB keyboard :)Durbar
You could probably base your code on qemu HID devices, seen in this and this.Mythopoeic

© 2022 - 2024 — McMap. All rights reserved.