Repository navigation
Releases
go-serial v0.6.0
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.
go-serial v0.5.0
Date: 2026-11-16
Previous release: v0.4.1
Summary
On Windows Close cancels a Read or Write in progress and Open takes a device name only. ErrTimeout matches os.ErrDeadlineExceeded, the errors of Close and of the RS-485 ioctl name the operation, and the new Config.VerifySettings makes Open on POSIX systems check that the port took the settings. The API change is additive: two Config fields.
Changes
Breaking
ErrTimeoutmatchesos.ErrDeadlineExceededwitherrors.Isand has aTimeout()method that reports true, like the time-outs ofnetandos. It is the same variable and does not matchcontext.DeadlineExceeded;errors.Is(err, serial.ErrTimeout)is unchanged. Who notices: code that tests foros.ErrDeadlineExceededor aTimeout()method and handles a match differently fromserial.ErrTimeout. Restore path: testserial.ErrTimeoutfirst.- The errors of
Closeand of the RS-485 ioctl name the operation:serial: close: …(withrestore termios,restore comm timeoutsorrestore comm statefor a failed restore) andserial: enable RS485: ….errors.Isstill reaches the cause. Who notices: code that compares the text of these errors. Restore path: match the cause, for example asyscall.Errno, witherrors.Is. - Windows:
Opentakes a device name only:COM3,COM3:,\\.\COM10, a\\?\device interface name,\\.\Global\NAMEor\\.\GLOBALROOT\Device\NAME. It opens the name in the device namespace, soCOM10and higher work without the prefix. Any other form fails with a*ConfigErrorforAddresswrappingErrInvalidConfigbefore anything is opened. Who notices: a program that opens a port through another form, such as a device interface path with a reference string or a link name with a path. Restore path:Config.UncheckedAddresspasses the address toCreateFileas given, as before; or use the port'sCOMname. - Windows:
Closecancels aReadorWritein progress withCancelIoEx, again every 10 ms until the call has returned, and only then restores the settings and closes the handle. The call returnsErrClosed, and so doReadandWriteafterClose. Before,Closeduring I/O was not supported, and I/O afterClosefailed with an error of the closed handle. Who notices: code that matched that error, or that relied on aClosereturning while a call was still in the driver. Restore path: none that keeps a closed handle in use; matcherrors.Is(err, serial.ErrClosed), which the POSIX backend returns since v0.4.0.
Added
Config.VerifySettings: on POSIX systemsOpenreads termios back after setting it and fails with a*ConfigErrorwrappingErrInvalidConfigwhen the port did not take the speed, data bits, stop bits or parity. On Linux withRS485.Enabledit also reads the RS-485 settings back (TIOCGRS485) and fails when the driver changed a delay. The error names the field and what the port reports;Openrestores the settings it found and closes the descriptor first. Off by default, soOpenbehaves as before: a Linux pseudo-terminal, for example, sets 8 data bits and no parity whatever it is given. No effect on Windows.Config.UncheckedAddress: on WindowsOpenpassesAddresstoCreateFileas given, as before v0.5.0. No effect on POSIX systems.
Documentation
- The package documentation, README, API.md, ERRORS.md, LIMITATIONS.md, SECURITY.md and ARCHITECTURE.md:
Closeon Windows, the Windows address rule,Config.VerifySettings,ErrTimeoutandos.ErrDeadlineExceeded, and the operation in error texts. - SECURITY.md: 0.5.x is the supported line from its release; 0.4.x until then.
- TESTING.md: the new tests, and Windows tests for rows L1, L3, L4 and L14 of the lifecycle table.
Tests and CI
- Windows, run by the
windows-latestjob against replacedReadFile,WriteFile,CancelIoExandCreateFile:Closeduring aReadand aWrite, a call that the first cancel missed,Closebetween twoWriteFilecalls, I/O afterClose, and the address check beforeCreateFile. - Every platform: the gate of the Windows
Closewithtesting/synctest, the Windows address check as a table test and asFuzzWindowsDeviceName, andErrTimeoutagainstos.ErrDeadlineExceeded,context.DeadlineExceededand the other sentinels. - POSIX: the comparison of termios as set and as read back, the RS-485 read-back against a replaced ioctl,
OpenwithConfig.VerifySettingsover a PTY, and the operation prefix of theCloseand RS-485 errors.
go-serial v0.4.1
Date: 2026-11-15
Previous release: v0.4.0
Summary
The Windows Write returns an error with a short count, OpenBSD waits for I/O with select, and the README states what is tested on each platform. No exported identifier changes.
Changes
Fixes
- Windows:
Writereturned a short count with a nil error whenConfig.Timeoutpassed before all bytes were written. It now returns the count withErrTimeout, as ERRORS.md and the comment onErrTimeoutsaid. A short count with no time-out set comes with an error wrappingio.ErrShortWrite. Code that took a nil error as "all bytes sent" now sees the error; code that wrote the rest again after a short count getsErrTimeoutinstead and decides for itself. - Windows: a buffer longer than one
WriteFilecall takes (2^32-1 bytes) is written in several calls. Before,Writewrote the first part and returned its length with a nil error. - OpenBSD:
Read, and aWritethat had to wait for room, failed with "function not implemented". The wait calledpollby its system call number, and on OpenBSD Go'ssyscallpackage carries out such calls for ioctl only. The wait now usessyscall.Select, with the code the macOS backend uses. This is cross-compiled and vetted, not run on OpenBSD. A descriptor at or aboveFD_SETSIZE(1024) fails withEINVALthere, as on macOS.
Changed
- POSIX:
Openchecks that the opened path is a character device before it reads or changes a terminal setting. Any other file is refused with an error wrappingENOTTY. Such a path could not be opened as a port before either: it failed one step later, with the error of the termios call./dev/nulland other character devices that are not terminals fail at the termios call, as before.
Documentation
- README: a table with the level of each platform (tested over pseudo-terminals, tested without a port, built and not run) and a list of what is known not to work.
- SECURITY.md: the supported line is 0.4.x; new sections on what the library trusts, its resource use and its known limits.
- ARCHITECTURE.md describes the mutex and the wake pipe of v0.4.0; before, it said that production code holds no locks and that
Closemust not run during I/O. - TESTING.md: where each group of tests runs, and the lifecycle contract tests (rows L1 to L16) with what applies to
Port. - LIMITATIONS.md: the Windows port is opened exclusively and the POSIX ones are not; on Windows, port numbers above 9 need the form
\\.\COM10; what CI runs on macOS, Windows and the BSDs. The "Known defects" entry is gone: the macOS failure ofTestChaosOpenCloseChurnwas in the test. - CONTRIBUTING.md lists what
make checkruns.
Tests and CI
TestCloseUnblocksReadandTestCloseUnblocksWriteno longer sleep. They hold the call at an unexported hook and assert thatClosedoes not return, and leaves the descriptor open, until theReadorWritehas let go of it.TestChaosOpenCloseChurnfailed on current macOS: the tests opened/dev/ptmxfrom eight goroutines at once. The test helper now opens it from one at a time, and the channel that collects the errors holds them all.- CI vets every cross-build target, which compiles its test files, and builds NetBSD and OpenBSD too. A
windows-latestjob runs the tests that need no port. The nightly workflow runs the tests as a linux/386 binary. - The release workflow builds and tests go-modbus against the release commit before it creates the tag. go-canbus is not listed: its SocketCAN tests need a kernel with AF_CAN, which that job does not set up.
go-serial v0.4.0
Date: 2026-11-14
Previous release: v0.3.0
Summary
Close cancels blocked I/O on POSIX systems, long timeouts are honoured on every platform, and the Windows backend returns available data with no timeout set.
Changes
Added
ErrClosed, returned on POSIX systems byReadandWriteon a closed port, and by aReadorWritethat was blocked whenCloseran in another goroutine.
Changed
- POSIX:
Closemay run concurrently withReadandWrite. It wakes them, waits until they have let go of the descriptor, then restores termios and closes it. Each port holds a pipe for this, so it uses two more descriptors. - POSIX:
ReadandWriteafterClosereturnErrClosedinstead of anEBADFerror. - macOS and the BSDs:
OpenwithConfig.RS485.Enabledfails withErrUnsupportedPlatforminstead of sending Linux's ioctl number. - Windows:
Closeis safe to call from several goroutines.
Fixes
- macOS:
Readfailed at once with "invalid argument" whenConfig.Timeoutwas above 10^8 seconds, whichselectdoes not accept. Longer waits are now made in several calls. - FreeBSD, NetBSD, OpenBSD: a
Config.Timeoutof 2^31 ms or more did not fitpoll's timeout argument. It is now clamped per call and waited in several calls. - Linux: the
ppolltimeout is clamped so 32-bit systems cannot truncate it. - Linux on MIPS: RS-485 used the wrong ioctl request number and could not be enabled.
- Windows: with
Timeout == 0,Readwaited for the whole buffer to fill. It now returns as soon as data arrives, as on POSIX. - Windows: a timeout below one millisecond turned into no timeout, and timeouts of 2^32 ms or more wrapped around. They are now rounded up and capped at 2^32-2 ms.
- Windows:
Openrejects baud rates above 2^32-1 instead of truncating them. - Windows: the DCB passed to
SetCommStatehas itsDCBlengthset; if setting the timeouts fails,Openrestores the previous DCB before closing. - Windows:
Readwith an empty buffer returns0, nilinstead ofErrTimeout. - The test package builds on 32-bit platforms.
Documentation
- LIMITATIONS.md: on Windows a
Writemay wait for a pendingRead(one synchronous handle), andReaddoes not report line errors (parity, framing, break).
go-serial v0.3.0
Date: 2026-11-12
Previous release: v0.2.1
Summary
Requires Go 1.26 (the OT Fabric floor) and rejects out-of-range values that were silently truncated.
Changes
Fixes
ParseDataBitsandParseStopBitschecked the value after converting it touint8, so out-of-range input such asParseDataBits(264)was accepted as 8. They now check theintfirst.Config.Validaterejects RS-485 RTS delays above the newMaxRS485Delay(2^32-1 ms), which the 32-bit kernel field cannot hold;Openrefuses them too. Before, they wrapped around.- The poll-based wait rejects a file descriptor outside the
int32range withEBADFinstead of truncating it.
Added
MaxRS485Delay.
Breaking changes
go.modnow saysgo 1.26.0; dependants need Go 1.26 or later. CI tests Go 1.26 and 1.27, and the cross-build uses thego.modversion.
go-serial v0.2.1
Date: 2026-10-31
Previous release: v0.2.0
Changed
- Policy 1.2: build output in
bin/andrelease/, a per-package coverage floor, and more tests and CI. No change in behaviour.
go-serial v0.2.0
Date: 2026-10-30
Previous release: v0.1.8
Summary
Fixes the serial mode on macOS and the BSDs.
Changes
Fixes
- Baud rate no longer changes the mode on macOS and the BSDs.
OpenORed
the speed constant intoCflag, where only Linux has a speed field. There
the constant is the numeric rate: at 9600 baudCflaghadCSTOPB(two
stop bits) andPARODDset, and at 1200 baudCSTOPB. The speed now goes
inIspeedandOspeedonly. Tested on macOS; the BSDs are built, not run.
Breaking changes
- None.
go-serial v0.1.8
Date: 2026-10-29
Previous release: v0.1.7
Summary
Patch release: two POSIX I/O bugs found by a new chaos test suite are fixed,
the module is go vet/lint clean on every supported platform (NetBSD now
compiles), and library test coverage rises from 77% to 96%.
Changes
Fixes
Readon file descriptors ≥ 1024.Readwaited withselect(2)and a
fixed 1024-entryfd_set. In a busy process the port can land above that
limit;Readthen returned a spuriousio.EOFat once and the kernel
accessed memory past the set. Linux and the BSDs now wait with
poll/ppoll, which has no descriptor limit. macOS keepsselect(its
polldoes not support ttys) and rejects such descriptors with an error.Writeunder backpressure. The descriptor is non-blocking, so once
the tty output buffer filled,Writereturned a short count with a nil
error, orn == -1withEAGAIN— silent data loss.Writenow waits
until the driver accepts more data and returns only when every byte is
written or an error occurs.- Timeouts under signals. Interrupted waits (
EINTR) retry against one
deadline, so signals no longer shorten or extend aReadtimeout.
SpuriousEAGAINwakeups inReadare retried. - I/O after
Closefails withEBADFinstead of blocking. - NetBSD builds again (
FdSetfield and termios speed types). - Windows:
CloseHandleresult checked on failed open; a port name
containing NUL returns an error instead of panicking;SyscallNreplaces
the deprecatedSyscall.
Tests
- POSIX error-path tests: termios options, failed opens, close, read and
write errors. Coverage 77.1% → 96.1%. - Chaos suite (
TestChaos*), seeded and reproducible via
SERIAL_CHAOS_SEED, scalable viaSERIAL_CHAOS_ITERATIONS: fragmenting
full-duplex relay, random hangups, signal storms during reads, ports above
FD_SETSIZE, write backpressure, random configs, concurrent open/close
churn with an fd-leak check, termios restore. - Fuzz targets for parsers, text round-trips,
Validate, and agreement
betweenValidateand the termios layer. TestReadWritemoved to the POSIX-only test file so Windows test builds
compile.
Unchanged
- The API. POSIX
Writestill has no timeout; it now blocks until all data
is written, as documented.
go-serial v0.1.7
Date: 2026-10-28
Previous release: v0.1.6
Summary
Patch release: POSIX Read now honours the io.Reader contract when a
read fails or the device goes away. Found while building go-canbus's slcan
transport, which drives USB CAN adapters through this package.
Changes
Fixes
Readnever returns a negative count. A failingread(2)used to
returnn == -1with the error; callers doingbuf[:n]panicked. It now
returnsn == 0.Readreportsio.EOFafter a hangup. Whenselect(2)reports the
device readable butread(2)returns no data, the other end hung up (an
unplugged USB adapter, a closed pseudo-terminal).Readused to return
(0, nil)forever; it now returnsio.EOF.
Tests
TestReadAfterHangupcloses the pseudo-terminal's other end and checks
thatReadends with an error andn == 0. It fails without the fix.
Unchanged
- Windows behaviour, the API and timeouts.
go-serial v0.1.6
Date: 2026-07-30
Previous release: v0.1.5
Summary
Patch release: document Port ownership, concurrency, timeouts, and Close
semantics; harden the Makefile. No API or behaviour changes.
Changes
Documentation
- Package docs (
serial.go) — Ownership afterOpen, one-reader/one-writer concurrency, timeout platform differences, Close vs blocked I/O. - README — New Ownership, concurrency, and Close section; Project structure summary; TOC updated.
Build / tooling
- Makefile
vuln—govulncheck ./..., included inmake check. - Makefile — exports
GOWORK=offso a parentgo.workthat omits this module does not break checks.
Unchanged
- No API, wire, or I/O behaviour changes. Concurrent Close with I/O remains unsupported (now documented).