Use the new find-device-port-macos script to find the correct port

pull/282/head
Michael Richters 7 years ago
parent 32ce579de1
commit c945bf0662

@ -0,0 +1,76 @@
#!/usr/bin/env perl
use warnings;
use strict;
# ioreg might be more machine-readable than system_profiler, but I haven't been able to
# get it to produce useful output
my @output = qx(/usr/sbin/system_profiler SPUSBDataType);
my $parse_state = 0;
my $device = {};
LINE: foreach my $line (@output) {
chomp $line;
if ( $parse_state == 0 ) {
if ( $line =~ m/Model 01/ ) {
$parse_state = 1;
next LINE;
}
}
if ( $parse_state == 1 ) {
if ( $line =~ m/^\s*$/ ) {
$parse_state = 2;
next LINE;
}
}
if ( $parse_state == 2 ) {
if ( $line =~ m/Serial Number: (.+)$/ ) {
$device->{'serial_number'} = $1;
next LINE;
}
if ( $line =~ m/Location ID: (.+)$/ ) {
$device->{'location_id'} = $1;
next LINE;
}
if ( $line =~ m/Product ID: (.+)$/ ) {
$device->{'product_id'} = $1;
next LINE;
}
if ( $line =~ m/Vendor ID: (.+)$/ ) {
$device->{'vendor_id'} = $1;
next LINE;
}
if ( $line =~ m/^\s*$/ ) {
last LINE;
}
}
}
die "Can't find Model 01" if ( $device == {} );
my $serial_port_name = "";
if ( exists( $device->{'serial_number'} ) ) {
$serial_port_name = "/dev/cu.usbmodem" . $device->{'serial_number'};
if ( -e $serial_port_name ) {
print $serial_port_name;
exit 0;
}
}
if ( exists( $device->{'location_id'} ) ) {
my $loc = substr( $device->{'location_id'}, 2, 4 );
$serial_port_name = "/dev/cu.usbmodem" . $loc . 1;
if ( -e $serial_port_name ) {
print $serial_port_name;
exit 0;
}
}
die "Can't find Model 01 serial port name";

@ -62,11 +62,9 @@ MD5="md5sum"
if [ "${uname_S}" = "Darwin" ]; then
find_device_port() {
DEVICE_PORT="$(ls /dev/cu.usbmodemkbio* 2> /dev/null || echo '')"
DEVICE_PORT="${DEVICE_PORT:-$(ls /dev/cu.usbmodemCkbio* 2> /dev/null || echo '')}"
DEVICE_PORT="${DEVICE_PORT:-$(ls /dev/cu.usbmodemHID* 2> /dev/null || echo '')}"
DEVICE_PORT="${DEVICE_PORT:-$(ls /dev/cu.usbmodemCHID* 2> /dev/null || echo '')}"
DEVICE_PORT="${DEVICE_PORT:-$(ls /dev/cu.usbmodem14* 2> /dev/null || echo '')}"
DIR=$(dirname "$0")
DEVICE_PORT_PROBER="${DIR}/find-device-port-macos"
DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER})"
}
reset_device_cmd() {
@ -80,8 +78,9 @@ if [ "${uname_S}" = "Darwin" ]; then
MD5="md5"
find_bootloader_ports() {
DEVICE_PORT_BOOTLOADER="$(ls /dev/cu.usbmodemkbio* 2> /dev/null || echo '')"
DEVICE_PORT_BOOTLOADER="${DEVICE_PORT_BOOTLOADER:-$(ls /dev/cu.usbmodem14* 2> /dev/null || echo '')}"
DIR=$(dirname "$0")
DEVICE_PORT_PROBER="${DIR}/find-device-port-macos"
DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER})"
}
fi

Loading…
Cancel
Save