From c945bf066250f5306b31d637d5f4428198369e81 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Wed, 10 Jan 2018 11:32:01 -0600 Subject: [PATCH 1/2] Use the new find-device-port-macos script to find the correct port --- bin/find-device-port-macos | 76 +++++++++++++++++++++++++++++++++++ etc/kaleidoscope-builder.conf | 13 +++--- 2 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 bin/find-device-port-macos diff --git a/bin/find-device-port-macos b/bin/find-device-port-macos new file mode 100644 index 00000000..93aed8aa --- /dev/null +++ b/bin/find-device-port-macos @@ -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"; diff --git a/etc/kaleidoscope-builder.conf b/etc/kaleidoscope-builder.conf index a7d8f747..b3379734 100644 --- a/etc/kaleidoscope-builder.conf +++ b/etc/kaleidoscope-builder.conf @@ -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 From 65ec30ae3211dfc8a67cfbb446b3952e2b1c3d45 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Mon, 15 Jan 2018 22:49:43 -0600 Subject: [PATCH 2/2] Added copyright & attribution comment --- bin/find-device-port-macos | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/find-device-port-macos b/bin/find-device-port-macos index 93aed8aa..464eed9e 100644 --- a/bin/find-device-port-macos +++ b/bin/find-device-port-macos @@ -1,5 +1,9 @@ #!/usr/bin/env perl +# Based on listArduinos.pl from https://github.com/todbot/usbSearch (License: MIT) +# Original (C) 2012, Tod E. Kurt, http://todbot.com/blog/ +# This version by Michael Richters + use warnings; use strict;