Skip to content

Commit 8ce3cfa

Browse files
sago35aykevl
authored andcommitted
flash: fix getDefaultPort() fails on Windows locales such as Japan
1 parent 904fa85 commit 8ce3cfa

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

main.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -603,29 +603,18 @@ func getDefaultPort() (port string, err error) {
603603
case "freebsd":
604604
portPath = "/dev/cuaU*"
605605
case "windows":
606-
cmd := exec.Command("wmic",
607-
"PATH", "Win32_SerialPort", "WHERE", "Caption LIKE 'USB Serial%'", "GET", "DeviceID")
608-
609-
var out bytes.Buffer
610-
cmd.Stdout = &out
611-
err := cmd.Run()
606+
ports, err := serial.GetPortsList()
612607
if err != nil {
613608
return "", err
614609
}
615610

616-
if out.String() == "No Instance(s) Available." {
611+
if len(ports) == 0 {
617612
return "", errors.New("no serial ports available")
613+
} else if len(ports) > 1 {
614+
return "", errors.New("multiple serial ports available - use -port flag")
618615
}
619616

620-
for _, line := range strings.Split(out.String(), "\n") {
621-
words := strings.Fields(line)
622-
if len(words) == 1 {
623-
if strings.Contains(words[0], "COM") {
624-
return words[0], nil
625-
}
626-
}
627-
}
628-
return "", errors.New("unable to locate a serial port")
617+
return ports[0], nil
629618
default:
630619
return "", errors.New("unable to search for a default USB device to be flashed on this OS")
631620
}

0 commit comments

Comments
 (0)