diff --git a/bin/find-device-port-macos b/bin/find-device-port-macos new file mode 100644 index 00000000..464eed9e --- /dev/null +++ b/bin/find-device-port-macos @@ -0,0 +1,80 @@ +#!/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; + +# 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