Identify Windows USB Sounddevice by physical USB port connection - windows

When I connect several USB audio devices using the default drivers I usually end up with some kind of friendly device description like "nn- USB Audio codec" or something else, so I have currently no unique property which refers to a specific hardware the e.g. manufacturer ID. I would like to ensure that in case of re-enumerating or replugging the hardware to a different port that my software will automatically identify the changed windows audio device which maps to this hardware. I there a possibility to gather further windows audio device information which can be used to determine the physical hardware ?
Maybe a little clarification is needed:
I have two or more USB audio devices, not necessarily same product or manufacturer. The audio connections have different purposes, so I want to ensure that I my software uses constantly the same physical audio devices for different tasks. This sometimes fails when a re-enumeration occurs ( sometimes without changing the physical USB port connections, it's a windows thing...)
Ideally I would distinguish them by an individual serial number, which usually is only available with storage devices. But what I can retrieve is the "physical" USB topology when I'm looking at the device with a tool such as USBDeview from Nir Sofer. There I have a property like "Hub 3, Port1". If I could map this to a sound device I get from audio audio api like "nn- USB Audio codec" as seen in the sound control panel I would be perfectly happy.
Edit2:
May be this[1] post helps here, but I still have to figure out how to get a USB Port <-> Windwos Sounddevice mapping.
[1]: Can the physical USB port be identified programatically for a device in Windows? "

Related

Is there an easy way to get low-level data from a Mac USB serial port, from devices that do not show up in the /dev/ directory?

What I want to achieve is that I plug in a device, for example a mouse, but in general any device that outputs serial data via USB, and then either screen it in terminal, or store it in a file and, if possible, use python to do things with it.
As a concrete example, let's say I want access to the data from a trackpad plugged into a USB port on a macbook. When I run /dev/{tty,cu}.* in terminal, I get a bunch of devices, but none of them is the one I want. When I run ioreg -p IOUSB -l -b | grep -E "#|PortNum|USB Serial Number", I see that the device is plugged in, at a specific address (i.e. #14200000), as well as <class AppleUSBDevice, id 0x100002c38, registered, matched, active, busy 0 (10 ms), retain 14> and "PortNum" = 2.
Yes, the device is plugged in, no it does not show up in /dev/{tty,cu}.*. I don't want to have to write a device driver, I have heard that it is not the easiest thing to do. Are there any solutions for accessing low-level data from devices that don't show up in the /dev/ directory?
Devices showing up as /dev/tty... and /dev/cu... are devices implementing the asynchronous serial data communication protocol derived from RS-232. There used to be dedicated serial ports on computers. Today on a Mac, they are usually connected via USB.
Few USB devices implement the serial protocol. Instead they implement the HID protocol (keyboard, mouse etc.), USB mass storage protocol (external drives of all kind), USB ECM (for network adapters) or a custom protocol. Except for the ones with a custom protocol, macOS provides device drivers for all of them.
USB isn't a simple serial communication. Instead, devices configure several endpoints. Each endpoint uses a separate communication channel. Even USB CDC ACM for RS-232 like communication uses three endpoints. In addition, USB devices can pretend to be several devices at once. This is call composite device.
My understanding is that you want to observe and record USB communication. The main approaches are:
Use Wireshark. It is well known for observing and recording network traffic but it can do the same for USB. Unfortunately, with the ever tighter security on macOS, it isn't so easy to set up and probably doesn't work on Apple Silicon Macs anymore.
Use a dedicated USB protocol analyzer. They are very powerful and start at about USD 300.

Device interface over USB

I have an usb device (pole display), which i don't have driver for.
I installed generic usb driver and opened the port for sending(I use bulk transfer) data to device.
With usb monitoring software i see my data gets to device, but nothing much happens on device side.
The device commands(ESC/POS) work when transfered over (virtual) com port, but not over usb port.
Shouldn't device process commands the same way regardless connection type (com vs usb)?
How can i figure out what commands work with the device (for example, if i send some text, i want it to show on display)?
Any help is appreciated!
Look at the USB descriptors the device reports in order to determine its class. If it is a custom device and not a standard class then you'll likely not be able to work with it. There is a big difference between old RS-232 COM protocol and USB. USB devices can have multiple configurations and endpoints, each responding to data in different ways. Many classes exist and are pretty standard (CDC-ACM is typically used for virtual serial ports.) However, it's not uncommon for device manufacturers to include OEM specific configurations and endpoints which can be used for their own custom interfaces, firmware loading, etc.
Is there any initialization data transmitted through the COM port when connecting the device? The device surely can treat COM and USB different, but another possible thing that goes wrong is that the device needs to hear some sort of "I'm going to start sending commands"-signal from you first, and that signal may be different between COM and USB.
So what I would recommend is first (if you have not done that yet) see what data is sent to initialize the COM connection, and if that doesn't have an obvious USB counterpart, connect it to a PC where you do have drivers (assuming that is available somewhere and somehow, which is possible if e.g. you ask this due to OS incompatibility) and see how the connection is initialized there.
If the first doesn't work and the second is unavailable to you, then I'm afraid there's little I can do to help you, since it's usually not visible for you what commands the device wants to hear other than by guesswork, documentation, or comparing to similar devices where you do have that data available.

Unique device identifiers for USB, firewire, and serial ports

I am working on a project that involves the auto-detection of USB and firewire devices being plugged and unplugged from an OS X system. For a given device, the system needs to recognise a device when it is plugged in (no matter which port) and load a device-specific bundle to deal with it.
The key to making this work is obviously the unique identification of each device. I know that USB devices are identified by a combination of the vendor ID and product ID fields, but this does not provide a unique ID, only the "kind" of device. If I have two devices the same and I plug both of them in to the computer, I would like some way to distinguish them. Is there a general and reliable way to do this, perhaps using other fields in the USB descriptor?
A related question, how does this work for USB serial ports? Suppose I plug in two USB serial ports of the same make/model. OS X should give them unique inodes in the /dev tree. However, suppose it calls them /dev/usbserial1 and /dev/usbserial2. If I then unplug the ports and plug in only one one of them, will that port be given the same name as it previously had, or will it just get /dev/usbserial1 (since it is the only) port plugged in?
Same question for firewire devices, although I think firewire devices are supposed to have a 64-bit GUID. In this case I am looking for someone to verify that using the GUID for firewire device identification would be reliable. In other words, if I plugged in two separate cameras of the same make and model, would I expect them to have different GUIDs?
I know I could test some of these with the appropriate hardware, but I don't have multiple bits of hardware at this time, so I am hoping someone may know at least some of the answers to the above questions.
With luck, your USB devices should have unique serial numbers, in addition to the VID/PID combination. If you're enumerating IOUSBDevice objects, look at the USB Serial Number property.
On Windows, Microsoft remembers device-specific settings by:
the device's serial number (the iSerialNumber field in the USB device descriptor), if available
or otherwise, by the "path" to the device: its bus (i.e. what hub it's plugged into etc.) + USB VID and PID
Without serial numbers, USB devices are virtually indistinguishable. You could tell apart different USB disk drives, but for devices which have no non-volatile memory of any kind (and many USB devices fall into this category), they are just indistinguishable, so you just have to make the best effort to do what the user expects.

Windows PC as a USB slave to emulate a thumbdrive

I need to create a application that will allow a Windows PC (XP/Vista) to emulate a thumbdrive. That is, when the PC is plugged into either another Windows system, or in this case, a piece of hardware that allows for USB thumbdrives to be plugged in, a folder on the computer looks like a giant thumbdrive. Any thoughts on where a guy would start to investigate this?
Update (more specific description):
I need to connect my PC to one of the newer multifuction devices that support scanning to a USB thumbdrive that is inserted into the front of the device. These units do not support WIA or TWAIN via the rear USB connector that you'd typically use for connectivity to a PC.
Most USB controllers in regular pc's dont have the possibility to function as an USB slave. So I'd start with investigating what kind of hardware you're going to use.
Another way to go: there are USB Link cables to link up 2 pc's over USB, maybe that's usable for you?
You cannot do this in an application. At the lowest level, the USB ports on your computer are controlled by an Host Controller Interface. This chip will manage up to 127 slave USB devices. You would need to seriously reprogram this chip before it implements the slave side of the USB protocol. Of course, at that point any USB hub in your PC will break down - those 8 USB ports you probably have are usually implemented by 2 smart USB hubs connecting to both USB1 and USB2 host controllers. Next, your USB keyboard and mouse will stop working.
Take an MCU with two Slave USBs. Write a simple frimware which makes one USB act as a Special Device Class and wait until PC on this USB provides mandatory data (including Device Class, of course) for the other USB. Write a PC program which connects to the Special Device (your MCU), uploads Mass Storage Device Class and redirects I/O to a dedicated partition. The other USB on the MCU will become an emulated Mass Storage Device.
Some of those code can be taken from Linux.

USB Debugging

I'm looking for a very specific USB device for debugging systems that may use USB but not with a regular computer (proprietary hardware). I want a device that has a USB host controller and two USB device connections. The device to be debugged is connected to the USB host controller and one of the device connections is connected to another device with it's own host controller on it. The the other device connection is connected to a pc. The point being that all USB data travelling through the device (from the device connected to the host controller to the device connected to the first device connection) is reported to the pc.
I'll happily write software to do the logging (in fact I want to) but I can't seem to find a board like this anywhere. Can anyone help?
I have an Ellisys USB analyser, which isn't exactly what you describe internally, but does sit between a peripheral and a host and use a separate PC to collect the data.
(i.e. it has two 'B' and one 'A' connectors on it.)
Excellent product, and very helpful company.
Sniffing the USB shouldn't be too hard if you have the right hardware. And that is the tricky question. I haven't seen anything that describes the USB breakout box that you want. However I can say that this is in the realm of the following two magazines:
Nuts and Volts
Circuit Cellar
If they don't have a USB breakout box project in their archives, then at least they will have advertisements for small cheap single board computers that would have multiple USB ports that you can use for buffering the signals and reporting it back to your PC.
Alternatively is it possible to just wire your PC up to the middle of your two devices and write a custom drive that echos data back and forth while sniffing off a stream for you?
Sorry for the long delay in my reply -- I checked out one of our USB developer's toolchain, and he uses a Beagle USB Sniffer. He seems happy with it.
You're looking for a USB device with two upstream outputs. I think according to the USB spec, this is not possible. You will have two USB hosts trying to send messages and control the USB devices at the same time.
What if you were to look for a device which allowed you to view the data going through a hub via something other than a usb output?
If you're building something custom, take a look at this USB chip site. The chips are programmable via a windows application. Once you define how you want it to operate, it's saved on an EPROM on the dev board ($30-$50).
Sorry if this isn't helpful!

Resources