serialport

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package serialport opens and configures a physical serial port on the host. It is the host end of `clawk serial` — internal/serialfwd carries the bytes, internal/cli/serial_proxy.go brokers them, and this is what actually talks to the tty.

Only what forwarding needs is here: open a port (possibly named by a glob), put it in raw mode, apply a line configuration the guest asked for, and read and write bytes until someone closes it. No enumeration, no modem-line control, no flow control — see the serialfwd package comment for why the last of those can't be plumbed through a PTY anyway.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMatch = errors.New("serialport: no device matches")

ErrNoMatch reports a device path that matched nothing. It is worth distinguishing because it is the ordinary "the board is unplugged, or is mid-reset" case, and the caller retries on it rather than giving up.

Functions

func Resolve

func Resolve(pattern string) (string, error)

Resolve turns a device pattern into a single concrete path. A literal path is returned once it is confirmed to exist, so an unplugged board fails here with ErrNoMatch rather than at open with a bare ENOENT.

Types

type Port

type Port struct {
	// contains filtered or unexported fields
}

Port is an open serial port.

It embeds no lock: Read and Write may be called concurrently (they are, by the two halves of the proxy's pump), which is safe on an *os.File, but two concurrent Writes will interleave and two concurrent Reads will race for bytes. The proxy runs exactly one of each.

func Open

func Open(pattern string, mode serialfwd.Mode) (*Port, error)

Open resolves pattern, opens the device, and puts it in raw mode with mode's line configuration.

pattern may be a literal path or a glob. A glob is resolved here, at open time, rather than when the device was configured: a board that reboots into its bootloader disappears from /dev and comes back — often under a neighbouring name — and re-globbing on each open is what lets a forward survive that. A glob matching several devices is an error rather than a guess, because picking the wrong board silently is worse than saying so.

func (*Port) Close

func (p *Port) Close() error

Close releases the port. On a tty configured by Open this lowers DTR, which on a board wired for auto-reset is half of the reset pulse the next Open completes — see the serialfwd package comment.

func (*Port) Configure

func (p *Port) Configure(mode serialfwd.Mode) error

Configure applies mode to the open port, leaving it in raw mode.

func (*Port) Path

func (p *Port) Path() string

Path is the resolved device this port is open on.

func (*Port) Read

func (p *Port) Read(b []byte) (int, error)

func (*Port) Write

func (p *Port) Write(b []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL