Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I keep track of a USB device across disconnections?

Tags:

macos

usb

iokit

I've got a bunch of USB serial devices (these to be precise: http://plugable.com/products/PL2303-DB9) and, if at all possible, I would like to "keep track" of them across unplug/replug events (even if the replug event is to a different USB port).

The driver appears to create their BSD dialin/callout/tty device names from their USB location, but this changes depending on which USB port you plug them into.

Looking at the IOKit property dictionaries between two identical devices plugged into two separate USB ports, the only differences are in sessionID, USB Address, locationID, portNum or in values that appear to be derived from the locationID. sessionID appears to change, well, per session (i.e. is different after every unplug/replug).

Since these devices all return 0 for iSerialNumber, I think I'm basically screwed here, but I figured I'd toss it out here and see if anyone has any ideas. Is there maybe some generic facility to write some "token" to a USB device that I can read back? I don't see anything in my quick skimming/googling of the USB standard, but a facility like that would certainly do the trick...

Any ideas?

like image 943
ipmcc Avatar asked Dec 06 '25 14:12

ipmcc


1 Answers

Unfortunately, there's no good way to do this (and if you figure one out, please post it here, as I've been trying to come up with one for years).

The problem, as you have surmised, is that there's no unique id on the device itself. If the devices had unique serial numbers (exposed in the IOKit property dictionaries), you could handle it, and if there were a little bit of user-addressable flash on the device that you could access, then you could write to it, but as far as I've been able to divine, there isn't any.

The only thing I've been able to do so far is keep track of the locations and tell people to connect the devices to the same ports if they want the devices to be recognized. However, in my case, I do have a predictable set of devices, which themselves handle serial numbers, so I am able to do a bit of this by querying the devices at the other end of the serial line directly.

like image 114
gaige Avatar answered Dec 09 '25 16:12

gaige