From 78207e546cba62a55d1d3ae6167abaf7c3be7752 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Wed, 21 Feb 2018 22:55:06 -0600 Subject: [PATCH] Improved fallbacks for macOS serial port detection Several people have reported difficulty flashing firmware on macOS High Sierra because the device port filename doesn't match the serial number from system_profiler. In particular, system_profiler would return a string ending in `E` whereas the device filename would have a `1`. This change adds a check for that filename explictily. I also corrected the location_id fallback (the substring should have been just 3 characters long, not 4), and it works properly on my system if I make the device shortname 7 characters long, and the filename reverts to using the location id instead. Last, I added one more check, simply listing the filenames, and searching for a match for the string `kbio01`, which should be present (although in one case, it wasn't). --- bin/find-device-port-macos | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bin/find-device-port-macos b/bin/find-device-port-macos index 464eed9e..002187e8 100644 --- a/bin/find-device-port-macos +++ b/bin/find-device-port-macos @@ -66,10 +66,19 @@ if ( exists( $device->{'serial_number'} ) ) { print $serial_port_name; exit 0; } + # High Sierra sometimes has a mismatch between the serial number and the device + # filename. I'm not sure why, but system_profiler has a serial number ending in "E", + # whereas the device filename ends in "1". Another possibility is that the device + # filename simply always ends in a "1". + $serial_port_name =~ s/E$/1/; + if ( -e $serial_port_name ) { + print $serial_port_name; + exit 0; + } } if ( exists( $device->{'location_id'} ) ) { - my $loc = substr( $device->{'location_id'}, 2, 4 ); + my $loc = substr( $device->{'location_id'}, 2, 3 ); $serial_port_name = "/dev/cu.usbmodem" . $loc . 1; if ( -e $serial_port_name ) { print $serial_port_name; @@ -77,4 +86,14 @@ if ( exists( $device->{'location_id'} ) ) { } } +# If none of the above tests succeeds, just list the directory and see if there are any +# files that have the device shortname that we expect: +foreach my $line (qx(ls /dev/cu.usbmodem*)) { + if ( $line =~ m/kbio01/ ) { + chomp $line; + print $line; + exit 0; + } +} + die "Can't find Model 01 serial port name";