Documentation ¶
Overview ¶
Package serial allows communication with serial ports.
Index ¶
- func CreateDUTPTYPair(ctx context.Context, dut *dut.DUT) (s1, s2 string, cancel func(), done <-chan error, err error)
- func CreateHostPTYPair(ctx context.Context) (s1, s2 string, cancel func(), done <-chan error, err error)
- func DoTestFlush(ctx context.Context, logf func(...interface{}), p1, p2 Port) error
- func DoTestRead(ctx context.Context, logf func(...interface{}), p1, p2 Port) error
- func DoTestWrite(ctx context.Context, logf func(...interface{}), p1, p2 Port) error
- type Config
- type ConnectedPort
- type ConnectedPortOpener
- type Port
- type PortOpener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateDUTPTYPair ¶
func CreateDUTPTYPair(ctx context.Context, dut *dut.DUT) (s1, s2 string, cancel func(), done <-chan error, err error)
CreateDUTPTYPair creates a pair of connected ptys on the DUT and returns their names, along with cancel and done to manage their lifetimes.
func CreateHostPTYPair ¶
func CreateHostPTYPair(ctx context.Context) (s1, s2 string, cancel func(), done <-chan error, err error)
CreateHostPTYPair creates a pair of connected ptys on the host and returns their names, along with cancel and done to manage their lifetimes.
func DoTestFlush ¶
DoTestFlush tests Port.Flush. This is used by both unit and integration tests and so should finish promptly.
func DoTestRead ¶
DoTestRead tests Port.Read. This is only used by integration tests due to the longer run time caused by a timeout from an intentional read operation when no data is available.
Types ¶
type Config ¶
type Config struct { // Name is the path on the filesystem to the port. Name string // Baud rate of the port. Baud int // ReadTimeout is the max expected duration of silence during reads. ReadTimeout time.Duration }
Config holds parameters of the serial port.
type ConnectedPort ¶
type ConnectedPort struct {
// contains filtered or unexported fields
}
ConnectedPort implements Port, delegates to tarm/serial.
func (*ConnectedPort) Close ¶
func (p *ConnectedPort) Close(ctx context.Context) error
Close closes the port.
func (*ConnectedPort) Flush ¶
func (p *ConnectedPort) Flush(ctx context.Context) error
Flush flushes un-read/written content from the port.
func (*ConnectedPort) Read ¶
Read reads bytes into provided buffer, returns number of bytes read. Bytes already written to the port shall be moved into buf, up to its size. In blocking mode (port opened without ReadTimeout), it blocks until at least one byte is read. In non-blocking mode, it may return an error with zero bytes read if ReadTimeout is exceeded, however this is not guaranteed on all platforms and so a context deadline exceeded error may be returned even though the deadline is greater than the ReadTimeout.
type ConnectedPortOpener ¶
type ConnectedPortOpener struct {
// contains filtered or unexported fields
}
ConnectedPortOpener opens a directly connected port on the localhost. In a dut context during local bundle execution, the localhost is the dut.
func NewConnectedPortOpener ¶
func NewConnectedPortOpener(name string, baud int, readTimeout time.Duration) *ConnectedPortOpener
NewConnectedPortOpener creates a new ConnectedPortOpener.
type Port ¶
type Port interface { // Read bytes into buffer and return number of bytes read. // Bytes already written to the port shall be moved into buf, up to its size. Read(ctx context.Context, buf []byte) (n int, err error) // Write bytes from buffer and return number of bytes written. // It returns a non-nil error when n != len(b), nil otherwise. Write(ctx context.Context, buf []byte) (n int, err error) // Flush un-read/written bytes. Flush(ctx context.Context) error // Close closes the port. Close(ctx context.Context) error }
Port represends a serial port and its basic operations.