Question

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?

Était-ce utile?

La solution

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.

Autres conseils

It's too bad the USB Serial driver framework doesn't force (or at least strongly recommend) that all drivers create /dev files using the device "Location ID".

It would seem to be the logical common value to use to identify devices by the physical port they are connected to. It is always provided, always unique, always specific to the physical port, doesn't change across reboots, doesn't change across removal and reinsertion if it is re-attached to the same physical port again, and doesn't rely on optional features such a serial numbers.

Meanwhile for those without serial numbers, such as the Prolific PL2303, the current driver (1.6.1, aka 1.6.0, on 10.13.6) makes up some random /dev/cu.usbserialN name each time the device is removed and re-attached (even if to the same port), and often it changes across reboots too.

For example here are three of my USB-Serial devices plugged into an external hub:

    USB2.0 Hub:

      Product ID: 0x0610
      Vendor ID: 0x05e3  (Genesys Logic, Inc.)
      Version: 92.12
      Speed: Up to 480 Mb/sec
      Manufacturer: GenesysLogic
      Location ID: 0x26400000 / 3
      Current Available (mA): 500
      Current Required (mA): 100
      Extra Operating Current (mA): 0

        USB-Serial Controller:

          Product ID: 0x2303
          Vendor ID: 0x067b  (Prolific Technology, Inc.)
          Version: 3.00
          Speed: Up to 12 Mb/sec
          Manufacturer: Prolific Technology Inc.
          Location ID: 0x26430000 / 8
          Current Available (mA): 500
          Current Required (mA): 100
          Extra Operating Current (mA): 0

        USB-Serial Controller:

          Product ID: 0x2303
          Vendor ID: 0x067b  (Prolific Technology, Inc.)
          Version: 3.00
          Speed: Up to 12 Mb/sec
          Manufacturer: Prolific Technology Inc.
          Location ID: 0x26420000 / 7
          Current Available (mA): 500
          Current Required (mA): 100
          Extra Operating Current (mA): 0

        FT232R USB UART:

          Product ID: 0x6001
          Vendor ID: 0x0403  (Future Technology Devices International Limited)
          Version: 6.00
          Serial Number: A603YGV3
          Speed: Up to 12 Mb/sec
          Manufacturer: FTDI
          Location ID: 0x26410000 / 6
          Current Available (mA): 500
          Current Required (mA): 90
          Extra Operating Current (mA): 0
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top