Skip to content

Commit f12391c

Browse files
authored
Merge pull request #205 from WarningImHack3r/fix-serial-getters
fix: incorrect masks for modem status bits on Windows
2 parents f0e4a45 + 8f447eb commit f12391c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

serial_windows.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,22 @@ func (port *windowsPort) SetRTS(rts bool) error {
281281
}
282282

283283
func (port *windowsPort) GetModemStatusBits() (*ModemStatusBits, error) {
284+
// GetCommModemStatus constants. See https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcommmodemstatus.
285+
const (
286+
MS_CTS_ON = 0x0010
287+
MS_DSR_ON = 0x0020
288+
MS_RING_ON = 0x0040
289+
MS_RLSD_ON = 0x0080
290+
)
284291
var bits uint32
285292
if err := windows.GetCommModemStatus(port.handle, &bits); err != nil {
286293
return nil, &PortError{}
287294
}
288295
return &ModemStatusBits{
289-
CTS: (bits & windows.EV_CTS) != 0,
290-
DCD: (bits & windows.EV_RLSD) != 0,
291-
DSR: (bits & windows.EV_DSR) != 0,
292-
RI: (bits & windows.EV_RING) != 0,
296+
CTS: (bits & MS_CTS_ON) != 0,
297+
DCD: (bits & MS_RLSD_ON) != 0,
298+
DSR: (bits & MS_DSR_ON) != 0,
299+
RI: (bits & MS_RING_ON) != 0,
293300
}, nil
294301
}
295302

@@ -366,7 +373,8 @@ func nativeOpen(portName string, mode *Mode) (*windowsPort, error) {
366373
0, nil,
367374
windows.OPEN_EXISTING,
368375
windows.FILE_FLAG_OVERLAPPED,
369-
0)
376+
0,
377+
)
370378
if err != nil {
371379
switch err {
372380
case windows.ERROR_ACCESS_DENIED:

0 commit comments

Comments
 (0)