Get /dev file name from IOreg?

Hi.

I have a class-compliant usb device which announces its serial number as m4121095, as per its kUSBSerialNumberString property. However, the file name it is provided is tty.usbmodemm41210951 – it's the serial number with an additional 1 at the end. What is the meaning of this appendage? (I'm tempted to believe that the 1 at the end is there in the unlikely case another device with the same SN is connected, but there's no way to test this possibility).

In the end, I would like to obtain a filename that is guaranteed to be representing a connection to exactly this device. Can I assume that the filename of a device that follows the same protocol of serial numbering will be consistently appended with a number that can in some way be inferred?

Thank you.

Accepted Reply

Thanks a lot for the response.

The main intention is indeed persistence across device reconnections, but I also expect to allow connections of multiple devices of the same make. Going through /dev filenames without knowing their precise schema looks unreliable.

I see that I have to leave IOUSB for this. I'm getting the paths alright, but now I have no access to its IOUSB representation, meaning I can't access its vendor, SN, etc.. Is it possible to retrieve the properties of IOUSBHostDevice that is served by a file and vice versa?

Could you expand on what you mean by this being a different question?

Replies

In the end, I would like to obtain a filename that is guaranteed to be representing a connection to exactly this device.

To what end?

If your goal is to open the /dev node, grab that from kIOCalloutDeviceKey property. For a concrete example, see the very-old-but-this-stuff-hasn’t-changed-much-in-decades Performing Serial I/O sample code.

If you’re goal is to maintain a persistent reference to the device — so that you can find it again after, say, an unplug and replug — that’s an entirely different question (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks a lot for the response.

The main intention is indeed persistence across device reconnections, but I also expect to allow connections of multiple devices of the same make. Going through /dev filenames without knowing their precise schema looks unreliable.

I see that I have to leave IOUSB for this. I'm getting the paths alright, but now I have no access to its IOUSB representation, meaning I can't access its vendor, SN, etc.. Is it possible to retrieve the properties of IOUSBHostDevice that is served by a file and vice versa?

Could you expand on what you mean by this being a different question?

whoops, pressed the checkmark by accident, I don't know how to remove it.

Ok, I managed to get the /dev file path by doing a DFS on IOUSBHostDevice children and matching for IOSerialBSDClient class.

I'm still interested in your explanation of "entirely different question". As I understand, there's no consistent and persistent ID between reconnections, and the only solution is to use the device's serial number, in case it is unique.

As I understand, there's no consistent and persistent ID between reconnections

Right. I/O Kit does not provide a general mechanism for persistent references, so you see a lot of different schemes depending on the context.

and the only solution is to use the device's serial number

That’s one option.

in case it is unique.

And that very much depends on the quality of the devices you’re using. If you expect to work with general USB serial hardware, you may well into problems here. USB isn’t really my area of expertise but I’ve heard horror stories from other folks here in DTS )-: For example, a device where all instances have the same serial number.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"