|
@ -998,7 +998,8 @@ func getDefaultPort(portFlag string, usbInterfaces []string) (port string, err e |
|
|
preferredPortIDs = append(preferredPortIDs, [2]uint16{uint16(vid), uint16(pid)}) |
|
|
preferredPortIDs = append(preferredPortIDs, [2]uint16{uint16(vid), uint16(pid)}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var primaryPorts []string // ports picked from preferred USB VID/PID
|
|
|
var primaryPorts []string // ports picked from preferred USB VID/PID
|
|
|
|
|
|
var secondaryPorts []string // other ports (as a fallback)
|
|
|
for _, p := range portsList { |
|
|
for _, p := range portsList { |
|
|
if !p.IsUSB { |
|
|
if !p.IsUSB { |
|
|
continue |
|
|
continue |
|
@ -1020,6 +1021,8 @@ func getDefaultPort(portFlag string, usbInterfaces []string) (port string, err e |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
secondaryPorts = append(secondaryPorts, p.Name) |
|
|
} |
|
|
} |
|
|
if len(primaryPorts) == 1 { |
|
|
if len(primaryPorts) == 1 { |
|
|
// There is exactly one match in the set of preferred ports. Use
|
|
|
// There is exactly one match in the set of preferred ports. Use
|
|
@ -1031,18 +1034,10 @@ func getDefaultPort(portFlag string, usbInterfaces []string) (port string, err e |
|
|
// one device of the same type are connected (e.g. two Arduino
|
|
|
// one device of the same type are connected (e.g. two Arduino
|
|
|
// Unos).
|
|
|
// Unos).
|
|
|
ports = primaryPorts |
|
|
ports = primaryPorts |
|
|
} |
|
|
} else { |
|
|
|
|
|
// No preferred ports found. Fall back to other serial ports
|
|
|
if len(ports) == 0 { |
|
|
// available in the system.
|
|
|
// fallback
|
|
|
ports = secondaryPorts |
|
|
switch runtime.GOOS { |
|
|
|
|
|
case "darwin": |
|
|
|
|
|
ports, err = filepath.Glob("/dev/cu.usb*") |
|
|
|
|
|
case "linux": |
|
|
|
|
|
ports, err = filepath.Glob("/dev/ttyACM*") |
|
|
|
|
|
case "windows": |
|
|
|
|
|
ports, err = serial.GetPortsList() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
default: |
|
|
default: |
|
|
return "", errors.New("unable to search for a default USB device to be flashed on this OS") |
|
|
return "", errors.New("unable to search for a default USB device to be flashed on this OS") |
|
|