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.

Community
  • 1
  • 1
Jader Dias
  • 88,211
  • 155
  • 421
  • 625

2 Answers2

20

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.

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
  • 1
    Just wanted to add a note : DSF has been deprecated -- http://msdn.microsoft.com/en-us/library/windows/hardware/br259131.aspx – Gishu Feb 06 '12 at 12:24
  • 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. – Gishu Feb 06 '12 at 12:51
  • 1
    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. @Gishu – Prof. Falken Feb 06 '12 at 12:56
  • 1
    You could use the USB IP project to emulate USB devices, as I demonstrated in [this](https://github.com/smulikHakipod/USB-Emulation) 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! – Yaron Shani Jan 22 '15 at 16:32
  • Cool example, @YaronShani. – Prof. Falken Jan 22 '15 at 18:25
3

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.

Yaron Shani
  • 176
  • 7
  • Really? How to duplicate USB keyboard :) – TomeeNS Jul 04 '16 at 08:19
  • You could probably base your code on qemu HID devices, seen in [this](https://github.com/qemu/qemu/blob/57528a3fef2fd65661320723ad8c3c781f4fd49f/hw/usb/dev-hid.c) and [this](https://github.com/qemu/qemu/blob/57528a3fef2fd65661320723ad8c3c781f4fd49f/hw/input/hid.c). – Yaron Shani Jul 08 '16 at 07:08