Merge pull request #300 from gedankenexperimenter/bug/macos-serial-port-mismatch

Improved fallbacks for macOS serial port detection
pull/301/head
Jesse Vincent 7 years ago committed by GitHub
commit b6fe847997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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";

Loading…
Cancel
Save