Skip to content

Commit

Permalink
Restore check for no detected serial ports on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jun 25, 2024
1 parent 1c72447 commit 56ac2d4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion serial_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package serial
*/

import (
"errors"
"sync"
"syscall"
"time"

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

func nativeGetPortsList() ([]string, error) {
key, err := registry.OpenKey(windows.HKEY_LOCAL_MACHINE, `HARDWARE\DEVICEMAP\SERIALCOMM\`, windows.KEY_READ)
if err != nil {
switch {
case errors.Is(err, syscall.ERROR_FILE_NOT_FOUND):
// On machines with no serial ports the registry key does not exist.
// Return this as no serial ports instead of an error.
return nil, nil
case err != nil:
return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err}
}
defer key.Close()
Expand Down

0 comments on commit 56ac2d4

Please sign in to comment.