serial

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package serial provides support for serial connections.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(name string) (io.ReadWriteCloser, error)

Open opens a new serial port using defaults.

func OpenWithOptions

func OpenWithOptions(name string, baudRate int) (io.ReadWriteCloser, error)

OpenWithOptions opens a new serial port with the given name and baud rate.

func RunCommands

func RunCommands(ctx context.Context, socket io.ReadWriteCloser, cmds []Command) error

RunCommands writes the provided commands to the serial socket.

func RunDiagnostics

func RunDiagnostics(ctx context.Context, socket io.ReadWriteCloser) error

RunDiagnostics runs a series of diagnostic commands over serial.

Types

type Command

type Command struct {
	Cmd           []string
	SleepDuration time.Duration
}

Command contains the command to run over serial and the expected duration to wait for the command to complete.

type SerialSocket

type SerialSocket struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewSocket

func NewSocket(ctx context.Context, socketPath string) (*SerialSocket, error)

NewSocket opens a connection on the provided `socketPath`.

func NewSocketWithIOTimeout

func NewSocketWithIOTimeout(ctx context.Context, socketPath string, ioTimeout time.Duration) (*SerialSocket, error)

NewSocketWithIOTimeout opens a connection on the provided `socketPath` with the provided socket IO timeout for reads and writes.

func (*SerialSocket) Read

func (s *SerialSocket) Read(p []byte) (int, error)

func (*SerialSocket) SetIOTimeout

func (s *SerialSocket) SetIOTimeout(timeout time.Duration)

SetIOTimeout sets the timeout for a single Read() or Write().

func (*SerialSocket) Write

func (s *SerialSocket) Write(p []byte) (int, error)

type Server

type Server struct {
	ServerOptions
	// contains filtered or unexported fields
}

Server proxies all i/o to/from a serial port via another io.ReadWriter. Start and Stop may be pairwise called any number of times.

func NewServer

func NewServer(serial io.ReadWriteCloser, opts ServerOptions) *Server

NewServer returns a new server that lives atop the given 'serial' port.

func (*Server) Run

func (s *Server) Run(ctx context.Context, listener net.Listener) error

Run begins the server and blocks until the context signals done or an error is encountered reading from serial. While running, all serial i/o is forwarded to and from the any connection accepted by the listener. The listener is closed by the time Run returns.

type ServerOptions

type ServerOptions struct {
	// AuxiliaryOutput is an optional path to a serial output sink.
	AuxiliaryOutput string

	// StartAtEnd instructs each connection to begin streaming at the end
	// of the aux file.
	StartAtEnd bool
}

ServerOptions provide options that parametrize the server's behavior.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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