flash: use more precise searches for correct volume/port with default Windows matching

Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
Ron Evans
2019-12-19 09:28:24 +01:00
committed by Ayke
parent 447537aebe
commit 18e446561d
+8 -8
View File
@@ -457,7 +457,7 @@ func flashUF2UsingMSD(volume, tmppath string) error {
case "darwin":
infoPath = "/Volumes/" + volume + "/INFO_UF2.TXT"
case "windows":
path, err := windowsFindUSBDrive()
path, err := windowsFindUSBDrive(volume)
if err != nil {
return err
}
@@ -484,7 +484,7 @@ func flashHexUsingMSD(volume, tmppath string) error {
case "darwin":
destPath = "/Volumes/" + volume
case "windows":
path, err := windowsFindUSBDrive()
path, err := windowsFindUSBDrive(volume)
if err != nil {
return err
}
@@ -502,10 +502,10 @@ func flashHexUsingMSD(volume, tmppath string) error {
return moveFile(tmppath, d[0]+"/flash.hex")
}
func windowsFindUSBDrive() (string, error) {
cmd := exec.Command("wmic", "PATH", "Win32_LogicalDisk",
"get", "DeviceID,", "VolumeName,",
"FileSystem,", "DriveType")
func windowsFindUSBDrive(volume string) (string, error) {
cmd := exec.Command("wmic",
"PATH", "Win32_LogicalDisk", "WHERE", "VolumeName = '"+volume+"'",
"get", "DeviceID,VolumeName,FileSystem,DriveType")
var out bytes.Buffer
cmd.Stdout = &out
@@ -559,8 +559,8 @@ func getDefaultPort() (port string, err error) {
case "linux":
portPath = "/dev/ttyACM*"
case "windows":
cmd := exec.Command("wmic", "PATH", "Win32_SerialPort",
"get", "DeviceID")
cmd := exec.Command("wmic",
"PATH", "Win32_SerialPort", "WHERE", "Caption LIKE 'USB Serial%'", "GET", "DeviceID")
var out bytes.Buffer
cmd.Stdout = &out