serial

package
v0.0.0-...-8023e94 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package serial provides support for serial connections.

Index

Constants

This section is empty.

Variables

View Source
var ErrNetClosing = errors.New("use of closed network connection")

ErrNetClosing comes from the stdlib, but is not exported by the stdlib, see https://golang.org/issues/4373. There is a test to assert this is still a sound match for the behavior we're matching against.

Functions

func IsErrNetClosing

func IsErrNetClosing(err error) bool

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.

Types

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 {
	// Logger if set to a non-nil value will receive log output for internal
	// errors that are incidental to program logic, but may be relevant for
	// diagnosis of general behaviors, such as errors in IO with the unix socket
	// clients.
	Logger *logger.Logger

	// AuxiliaryOutput is an optional serial output sink. It will be closed before
	// server.Run returns. It is dup'd for each incoming socket.
	AuxiliaryOutput *os.File

	// 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.

Jump to

Keyboard shortcuts

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