26

On linux USB-serial devices create two aliases to its serial port:
/dev/tty* and /dev/serial/by-id/<my_usb_device_id>

Is there a way on OSX to identify a serial port by the USB device id? Both in System Profiler and using ioreg -p IOUSB I can see the id, but that doesn't get me any closer to connecting using that id.

We're developing several pieces of hardware and it's a pain to test them as every time I connect a different device I need to verify the serial port configuration of the testing software, because on OSX the tty.* port name depends on the port on my computer, not on the device. The guys running linux are happily using the /dev/serial/by-id/<my_usb_device_id> port to automatically distinguish between the different devices.

5 Answers 5

9

Actually, you should be able to find the mapping from device ID/serial number to serial port name using ioreg. Try this command:

ioreg -r -c IOUSBHostDevice -l

It will print all the USB host devices, and it will print out all properties from the subtree of each device. You should be able to find your device on the top level based on its ID or serial number. Once you've found it, you should be able to scan through its subtree, and eventually find an object of class IOSerialBSDClient. This will contain the property IODialinDevice which is what you want.

If you then want to do this programmatically, you could add the -a option to the ioreg command, which will output a plist version of the above output. You could then parse this with a library such as plistlib.

You might find it helpful to use the IORegistryExplorer app to help visualise this, as the full ioreg output is slightly difficult to read! This is available in XCode's "Hardware IO Tools" package which you can find by searching the downloads on the Apple developer site. Here's what it looks like on my device:

IORegistryExplorer example

1
  • 2
    Please note that IORegistryExplorer.app is now bundled onto a .dmg called "Additional Tools for Xcode", still at the same URL.
    – Anthony
    Commented Aug 27, 2022 at 13:42
5

According to my experience, this problem comes from the driver of your serial to uart device. normally you should be able to access the serial port using

ls /dev/tty*.* 

and this is the only way to do it. But if your mac does not show it, i installed a program called serial detect, and it detected my board, otherwise use lusb before and after connecting the board, if you don't have it, install it as follows

brew install lsusb 

according to my device, i needed the following driver, for my mac 10.13

https://www.silabs.com/community/interface/knowledge-base.entry.html/2017/01/10/legacy_os_softwarea-bgvU

once installed, you can find it by

ls /dev/tty*.*

now you can flash your device or open the serial port. You can access the usb device using the device id using dfu-util, in my case 1d50:6017 is the device id shown in lsusb, i used it for flashing a blackmagic probe but you can flash what you want, dfu-util is a free utility can be installed with brew install --build-from-source dfu-util

dfu-util -d 1d50:6017 -s 0x08002000:leave -D ./src/blackmagic.bin
1
  • 2
    There's no way for me to do any testing on this issue any more as the project was finished many years ago and I'm not doing full time hardware development any more. But as I noted in my original post, the device id was directly dependent on the port on my laptop, not the hardware I plugged in. I have two USB-A ports and each time I plugged in a piece of hardware being developed, I had to check the custom built testing/operating software configuration to make sure it had the correct id to communicate with the device.
    – Johan
    Commented Jan 19, 2021 at 9:52
2

For an FTDI bridge I have, the serial number already appears in the device name: it appears as /dev/serial/by-id/usb-FTDI_FT231X_USB_UART_DA00AG57-if00-port0 (corresponding to some /dev/ttyUSBx) on Linux, and as /dev/cu.usbserial-DA00AG57 and /dev/tty.usbserial-DA00AG57 on macOS. (See https://stackoverflow.com/a/8632603/4896937 for difference between tty.* and cu.*.)

Unfortunately, for Prolific bridge I have, an issue like yours still applies: a device appearing as /dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0 (which doesn't contain a serial number) is simply /dev/cu.usbserial and /dev/tty.usbserial on macOS (not even System Profiler gives a serial number for it). Who knows what would happen if I had a second one plugged in.

Maybe there is a more general answer out there that is vendor-independent, but be warned some devices might not report a serial number.

1
  • For me they appear as /dev/tty.usbmodemFD121 and /dev/tty.usbmodemFA131. The number depends directly on the USB port on my laptop. System info shows the correct id for the devices set by their firmware. Both serials are created by STM32F2/F4 processors.
    – Johan
    Commented Feb 6, 2017 at 8:16
1

I used the output of ioreg and added some parsing with perl to output a csv of serial ports in relation to usb information (like VID, PID, SN).

ioreg -r -c IOUSBHostDevice -x -l | perl -ne 'BEGIN {print "USB Serial Number,idProduct,idVendor,IOCalloutDevice\n"} /"USB Serial Number" = "(.+)"/ && ($sn=$1); /"idProduct" = (.+)/ && ($ip=$1); /"idVendor" = (.+)/ && ($iv=$1); /"IOCalloutDevice" = "(.+)"/ && print "$sn,$ip,$iv,$1\n"'

Example output:

USB Serial Number,idProduct,idVendor,IOCalloutDevice
123456,0x1234,0xaabb,/dev/cu.usbmodem1234561
987654,0xabcd,0xaabb,/dev/cu.usbmodem9876542
000001,0x4321,0xccdd,/dev/cu.usbmodem0000013

This output can easily be parsed or used in conjunction with grep to find the desired device and serial port

Explanation:

  • ioreg -r -c IOUSBHostDevice -x -l list usb host devices, use -x for hexadecimal output
  • perl -ne <command> to parse the ioreg output, -n iterates over output line by line, -e runs specified command
  • BEGIN {print "USB Serial Number,idProduct,idVendor,IOCalloutDevice\n"} prints csv header
  • /"USB Serial Number" = "(.+)"/ && ($sn=$1); matches a pattern and stores captured value in a variable $sn
  • /"idProduct" = (.+)/ && ($ip=$1); /"idVendor" = (.+)/ && ($iv=$1); same as above
  • /"IOCalloutDevice" = "(.+)"/ && print "$sn,$ip,$iv,$1\n" whenever there is a line containing IOCalloutDevice we know we're dealing with a serial port (you could change this to IODialinDevice for tty instead of cu). Print the serial port and last stored usb infos (which always come before in the ioreg output) as ,-delimited line.
1
  • 1
    Seems like a plausible solution, but as I commented before, I have no way of testing this any more. Thanks for the answer anyway. It may help someone else in the future.
    – Johan
    Commented Jan 12 at 19:56
0

I had the same issue with Profilic Bridge and download the driver from http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=229&pcid=41 fix the problem after restart.

2
  • 1
    What problem was that? The OP asked how to identify a device, there’s no mention of having driver issues.
    – Allan
    Commented Mar 23, 2020 at 11:24
  • This is the correct answer, i have been searching alot Commented Jan 17, 2021 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .