Repository navigation
Date: 2026-11-19
Previous release: v0.5.0
Summary
Flow control and modem lines. Config.FlowControl sets RTS/CTS or XON/XOFF flow control on every platform and DTR/DSR on Windows; the port Open returns implements the new ModemLines interface, which sets DTR and RTS and reads CTS, DSR, RI and DCD. The API change is additive: one Config field, the FlowControl type, the ModemLines interface, ModemStatus and ErrLineInUse. Port is unchanged, so code that implements it keeps compiling.
Contributed by @MatthewReed303 in #18. Thank you.
Changes
Added
Config.FlowControl(FlowNone,FlowRTSCTS,FlowDTRDSR,FlowXONXOFF) andParseFlowControl. POSIX:CRTSCTS, orIXONandIXOFFwithVSTARTandVSTOPset toXONandXOFF;FlowDTRDSRfailsOpenwithErrUnsupportedPlatform. Windows: the DCB's handshake flags, orfOutXandfInXwith the driver's XON and XOFF thresholds.ValidaterefusesFlowRTSCTSwithRS485.Enabled, andConfig.VerifySettingscompares the flow control too.ModemLines(SetDTR,SetRTS,ModemStatus) andModemStatus, implemented by the portOpenreturns:TIOCMBIS,TIOCMBICandTIOCMGETon POSIX systems,EscapeCommFunctionandGetCommModemStatuson Windows.ErrLineInUse:SetRTSunder RTS/CTS flow control or RS-485,SetDTRunder DTR/DSR flow control.XONandXOFF.ExampleParseFlowControlandExampleModemLines.
The ModemLines methods on a closed port return ErrClosed, also for a line that flow control or RS-485 drives. Close restores the flow control with the saved termios or DCB, but not the levels SetDTR and SetRTS set.
Documentation
- The package documentation (concurrency of the
ModemLinesmethods), README (features and the comparison table), API.md, ARCHITECTURE.md (the new files, theModemLinesmethods under the close gate, whatCloserestores), ERRORS.md, LIMITATIONS.md (flow control and modem lines per platform, and what no test proves on hardware), SECURITY.md and TESTING.md.
Tests and CI
- Every platform:
FlowControlparsing, text and validation, and the Windows DCB flags,EscapeCommFunctionfunctions andGetCommModemStatusbits against the Win32 header values. - POSIX: the flow-control termios bits and their read-back,
Openwith each flow control over a PTY, XON/XOFF holding output over a PTY until XON, and the modem-line ioctls against a replaced ioctl. - Windows: the DCB of each flow control, and the modem-line methods of a closed port.
- Chaos:
TestChaosModemLinesDuringClose(the modem-line methods from several goroutines duringRead,Writeand a racingClose); random configs and the termios restore now include the flow control. - Fuzz:
FuzzParseFlowControl; the flow control inFuzzTextRoundTrip,FuzzConfigValidateandFuzzTermiosAgreesWithValidate.