Documentation
¶
Overview ¶
Package serialport opens host serial devices and applies line settings.
The Port interface exists so the broker can be tested without hardware: see internal/serialtest for a pty-backed fake. Line settings are expressed in plain values here (baud as a number, 5-8 data bits) rather than in RFC2217 or termios encodings, so neither the wire format nor the kernel's bit layout leaks into the broker.
Index ¶
Constants ¶
const ( ParityNone uint8 = iota ParityOdd ParityEven )
Parity values.
const ( FlowNone uint8 = iota FlowRTSCTS FlowXONXOFF )
Flow control values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Modem ¶
Modem holds the output control lines.
These are the lines a pty cannot represent, and the reason moat speaks RFC2217: toggling DTR and RTS in sequence is how an ESP32 is driven into its bootloader.
type ModemStatus ¶
type ModemStatus struct {
CTS bool // Clear To Send
DSR bool // Data Set Ready
RI bool // Ring Indicator
CD bool // Carrier Detect
}
ModemStatus is the readable input control lines. USB-serial adapters report a subset — a line the adapter does not wire reads as false.
type Port ¶
type Port interface {
io.ReadWriteCloser
// ApplySettings sets baud, framing, and flow control. Zero-valued fields
// are left unchanged.
ApplySettings(Settings) error
// SetModem drives the DTR and RTS output lines.
SetModem(Modem) error
// ModemStatus reads the CTS, DSR, RI, and CD input lines. It backs
// RFC2217 NOTIFY-MODEMSTATE, which pyserial-based tools read for flow
// control and carrier detection.
ModemStatus() (ModemStatus, error)
// SendBreak transmits a break condition.
SendBreak() error
// FlushBuffers discards pending input and output on the device. It backs
// RFC2217 PURGE_DATA, which pyserial's client issues from inside
// Serial.open() and blocks on — a server that ignores it fails every
// pyserial connect, not just explicit flush calls.
FlushBuffers() error
// Name is the host device path, for logs and errors.
Name() string
}
Port is an open serial device.
func Open ¶
Open opens a serial device.
It refuses anything that is not a tty, and that check is the device-class allowlist: storage, HID, and smartcard devices do not present as ttys, so there is no separate deny list that could drift out of sync with it.
The port is opened non-blocking so Go's poller owns the fd, which lets Close interrupt a blocked Read — the broker relies on that to tear a session down.
type Settings ¶
type Settings struct {
Baud uint32 // e.g. 115200; 0 means "leave unchanged"
DataBits uint8 // 5-8; 0 means "leave unchanged"
StopBits uint8 // 1 or 2; 0 means "leave unchanged"
Parity uint8 // ParityNone, ParityOdd, ParityEven
FlowControl uint8 // FlowNone, FlowRTSCTS, FlowXONXOFF
}
Settings are the line settings of a serial port.