Repository navigation
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.