serial

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package serial allows communication with serial ports.

Index

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

func DoTestFlush(ctx context.Context, logf func(...interface{}), p1, p2 Port) error

DoTestFlush tests Port.Flush. This is used by both unit and integration tests and so should finish promptly.

func DoTestRead

func DoTestRead(ctx context.Context, logf func(...interface{}), p1, p2 Port) error

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.

func DoTestWrite

func DoTestWrite(ctx context.Context, logf func(...interface{}), p1, p2 Port) error

DoTestWrite tests Port.Write. This is used by both unit and integration tests and so should finish promptly.

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

func (p *ConnectedPort) Read(ctx context.Context, buf []byte) (n int, err error)

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.

func (*ConnectedPort) Write

func (p *ConnectedPort) Write(ctx context.Context, buf []byte) (n int, err error)

Write writes bytes from provided buffer, returns number of bytes written. It returns a non-nil error when n != len(b), nil otherwise.

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.

func (*ConnectedPortOpener) OpenPort

func (c *ConnectedPortOpener) OpenPort(ctx context.Context) (Port, error)

OpenPort opens the port.

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.

type PortOpener

type PortOpener interface {
	OpenPort(context.Context) (Port, error)
}

PortOpener opens the serial port.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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