Skip to content

Commit 56ac2d4

Browse files
committed
Restore check for no detected serial ports on Windows
1 parent 1c72447 commit 56ac2d4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

serial_windows.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package serial
1818
*/
1919

2020
import (
21+
"errors"
2122
"sync"
23+
"syscall"
2224
"time"
2325

2426
"golang.org/x/sys/windows"
@@ -32,7 +34,12 @@ type windowsPort struct {
3234

3335
func nativeGetPortsList() ([]string, error) {
3436
key, err := registry.OpenKey(windows.HKEY_LOCAL_MACHINE, `HARDWARE\DEVICEMAP\SERIALCOMM\`, windows.KEY_READ)
35-
if err != nil {
37+
switch {
38+
case errors.Is(err, syscall.ERROR_FILE_NOT_FOUND):
39+
// On machines with no serial ports the registry key does not exist.
40+
// Return this as no serial ports instead of an error.
41+
return nil, nil
42+
case err != nil:
3643
return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err}
3744
}
3845
defer key.Close()

0 commit comments

Comments
 (0)