Restore check for no detected serial ports on Windows
This commit is contained in:
@@ -18,7 +18,9 @@ package serial
|
||||
*/
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user