Documentation
¶
Overview ¶
Package serial opens local serial ports as terminal byte streams. It wraps a swappable Backend (go.bug.st/serial by default) behind its own types, so callers never see the backend's.
Index ¶
Constants ¶
const DefaultBaud = 115200
DefaultBaud is the baud rate of a Config that names none.
Variables ¶
var ( ErrNotFound = errors.New("serial: no such port") ErrBusy = errors.New("serial: port in use") ErrPermission = errors.New("serial: permission denied") ErrInvalidConfig = errors.New("serial: invalid settings") ErrDisconnected = errors.New("serial: device disconnected") )
Errors returned by Open and by a Port's Read; each wraps the original cause.
var Bauds = []int{300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600}
Bauds are the baud rates offered as choices; any positive rate is allowed.
Functions ¶
Types ¶
type Backend ¶
type Backend interface {
// Open opens a normalized, validated Config.
Open(Config) (Port, error)
// Ports lists the serial devices present, in any order.
Ports() ([]string, error)
}
Backend opens ports and lists devices.
var Default Backend = bugst{}
Default is the Backend Open and Ports use: go.bug.st/serial.
type Config ¶
type Config struct {
Device string
Baud int // 0 means DefaultBaud
DataBits int // 0 means 8; valid 5..8
Parity Parity // "" means none
StopBits StopBits // "" means 1
}
Config is how to open a port.
func (Config) Frame ¶
Frame is the conventional short form of the normalized framing, such as "8N1" or "7E1.5".
func (Config) Normalized ¶
Normalized fills in defaults and tidies Device (on Windows "com3" and `\\.\COM3` become "COM3").
type Port ¶
type Port interface {
io.ReadWriteCloser
Break(d time.Duration) error
SetDTR(on bool) error
SetRTS(on bool) error
}
Port is an open serial port. Read blocks until data arrives; after Close it returns io.EOF, and if the device goes away it returns an error wrapping ErrDisconnected. Close is idempotent and may run concurrently with a blocked Read.