Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions serial_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package serial

import (
"errors"
"strings"
"sync"
"syscall"
"time"
Expand All @@ -45,12 +46,22 @@ func nativeGetPortsList() ([]string, error) {
}
defer key.Close()

list, err := key.ReadValueNames(0)
names, err := key.ReadValueNames(0)
if err != nil {
return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err}
}

return list, nil
var values []string
for _, n := range names {
v, _, err := key.GetStringValue(n)
if err != nil || v == "" {
continue
}

values = append(values, v)
}

return values, nil
}

func (port *windowsPort) Close() error {
Expand Down Expand Up @@ -342,7 +353,9 @@ func createOverlappedEvent() (*windows.Overlapped, error) {
}

func nativeOpen(portName string, mode *Mode) (*windowsPort, error) {
portName = "\\\\.\\" + portName
if !strings.HasPrefix(portName, `\\.\`) {
portName = `\\.\` + portName
}
path, err := windows.UTF16PtrFromString(portName)
if err != nil {
return nil, err
Expand Down