Merge pull request #205 from WarningImHack3r/fix-serial-getters
Some checks failed
test / native-os-build (macOS-latest) (push) Has been cancelled
test / native-os-build (ubuntu-latest) (push) Has been cancelled
test / native-os-build (windows-latest) (push) Has been cancelled
test / cross-os-build (freebsd amd64) (push) Has been cancelled
test / cross-os-build (linux ppc64le) (push) Has been cancelled
test / cross-os-build (openbsd 386) (push) Has been cancelled
test / cross-os-build (openbsd amd64) (push) Has been cancelled
test / cross-os-build (openbsd arm) (push) Has been cancelled

fix: incorrect masks for modem status bits on Windows
This commit is contained in:
Cristian Maglie
2025-05-19 15:36:16 +02:00
committed by GitHub

View File

@@ -281,15 +281,22 @@ func (port *windowsPort) SetRTS(rts bool) error {
}
func (port *windowsPort) GetModemStatusBits() (*ModemStatusBits, error) {
// GetCommModemStatus constants. See https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcommmodemstatus.
const (
MS_CTS_ON = 0x0010
MS_DSR_ON = 0x0020
MS_RING_ON = 0x0040
MS_RLSD_ON = 0x0080
)
var bits uint32
if err := windows.GetCommModemStatus(port.handle, &bits); err != nil {
return nil, &PortError{}
}
return &ModemStatusBits{
CTS: (bits & windows.EV_CTS) != 0,
DCD: (bits & windows.EV_RLSD) != 0,
DSR: (bits & windows.EV_DSR) != 0,
RI: (bits & windows.EV_RING) != 0,
CTS: (bits & MS_CTS_ON) != 0,
DCD: (bits & MS_RLSD_ON) != 0,
DSR: (bits & MS_DSR_ON) != 0,
RI: (bits & MS_RING_ON) != 0,
}, nil
}
@@ -366,7 +373,8 @@ func nativeOpen(portName string, mode *Mode) (*windowsPort, error) {
0, nil,
windows.OPEN_EXISTING,
windows.FILE_FLAG_OVERLAPPED,
0)
0,
)
if err != nil {
switch err {
case windows.ERROR_ACCESS_DENIED: