From 29730ad94e67db71085142e181063841a3373377 Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Fri, 28 Jul 2017 10:04:49 +0200 Subject: [PATCH] Add RTS and DTR to GetModemStatusBits for windows --- serial.go | 2 ++ serial_windows.go | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/serial.go b/serial.go index 46eb521..87857d3 100644 --- a/serial.go +++ b/serial.go @@ -51,6 +51,8 @@ type ModemStatusBits struct { DSR bool // DataSetReady status RI bool // RingIndicator status DCD bool // DataCarrierDetect status + RTS bool // ReadyToSend status (outgoing) + DTR bool // DataTerminalReady status (outgoing) } // Open opens the serial port using the specified modes diff --git a/serial_windows.go b/serial_windows.go index 4a504ef..8081619 100644 --- a/serial_windows.go +++ b/serial_windows.go @@ -144,7 +144,7 @@ const ( dcbInX = 0x00000200 dcbErrorChar = 0x00000400 dcbNull = 0x00000800 - dcbRTSControlDisbaleMask = ^uint32(0x00003000) + dcbRTSControlDisableMask = ^uint32(0x00003000) dcbRTSControlEnable = 0x00001000 dcbRTSControlHandshake = 0x00002000 dcbRTSControlToggle = 0x00003000 @@ -303,7 +303,7 @@ func (port *windowsPort) SetRTS(rts bool) error { if err := getCommState(port.handle, params); err != nil { return &PortError{causedBy: err} } - params.Flags &= dcbRTSControlDisbaleMask + params.Flags &= dcbRTSControlDisableMask if rts { params.Flags |= dcbRTSControlEnable } @@ -314,15 +314,22 @@ func (port *windowsPort) SetRTS(rts bool) error { } func (port *windowsPort) GetModemStatusBits() (*ModemStatusBits, error) { - var bits uint32 - if !getCommModemStatus(port.handle, &bits) { + var modemStatus uint32 + if !getCommModemStatus(port.handle, &modemStatus) { return nil, &PortError{} } + var commState dcb + if err := getCommState(port.handle, &commState); err != nil { + return nil, &PortError{causedBy: err} + } + return &ModemStatusBits{ - CTS: (bits & msCTSOn) != 0, - DCD: (bits & msRLSDOn) != 0, - DSR: (bits & msDSROn) != 0, - RI: (bits & msRingOn) != 0, + CTS: (modemStatus & msCTSOn) != 0, + DCD: (modemStatus & msRLSDOn) != 0, + DSR: (modemStatus & msDSROn) != 0, + RI: (modemStatus & msRingOn) != 0, + RTS: (commState.Flags & dcbRTSControlEnable) != 0, + DTR: (commState.Flags & dcbDTRControlEnable) != 0, }, nil } @@ -369,7 +376,7 @@ func nativeOpen(portName string, mode *Mode) (*windowsPort, error) { port.Close() return nil, &PortError{code: InvalidSerialPort} } - params.Flags &= dcbRTSControlDisbaleMask + params.Flags &= dcbRTSControlDisableMask params.Flags |= dcbRTSControlEnable params.Flags &= dcbDTRControlDisableMask params.Flags |= dcbDTRControlEnable