sers

package module
v2.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sers offers serial port access. It is a stated goal of this package to allow for non-standard bit rates as the may be useful in a wide range of embedded projects.

Index

Constants

View Source
const (
	N = 0 // no parity
	E = 1 // even parity
	O = 2 // odd parity
)
View Source
const (
	NO_HANDSHAKE     = 0
	RTSCTS_HANDSHAKE = 1
)
View Source
const (
	STOPBITS_1 = 0
	STOPBITS_2 = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Operation       string
	UnderlyingError error
}

func (*Error) Error

func (e *Error) Error() string

type Mode

type Mode struct {
	Baudrate  int
	DataBits  int
	Parity    int
	Stopbits  int
	Handshake int
}

func ParseModestring

func ParseModestring(s string) (Mode, error)

Parses a modestring like "115200,8n1,rtscts" into a struct Mode. The format is baudrate,framestring,handshake. Either the handshake part or both the framestring and handshake parts can be omitted. For the omitted parts, defaults of 8 data bits, no parity, 1 stop bit and no handshaking will be filled in. The framestring consists of a sequence databits, parity, stopbits. Any or all of the three components can be left out. Non-specified parts will take the default values mentioned before.

Valid choices for databits are [5, 6, 7, 8], for parity it is [n, o, e] and for stopbits it's [1, 2]. Valid choices for the handshake parts are "", "none" and "rtscts". The function is not case sensitive.

A couple of examples:

60000	         - 60000 baud, 8 data bits, no parity, 1 stopbit, no handshake
115200,8e1       - 115200 baud, 8 data bits, even parity, 1 stopbit, no handshake
57600,8o1,rtscts - 57600 baud, 8 data bits, odd parity, 1 stopbit, rts/cts handshake
19200,72		 - 19200 baud, 7 data bits, no parity, 2 stop bits, no handshake
9600,2,rtscts    - 9600 baud, 8 data bits, no parity, 2 stop bits, rts/cts handshake

func (Mode) String

func (m Mode) String() string

func (Mode) Valid

func (m Mode) Valid() bool

type ParameterError

type ParameterError struct {
	Parameter string
	Reason    string
}

func (*ParameterError) Error

func (pe *ParameterError) Error() string

type SerialPort

type SerialPort interface {
	io.Reader
	io.Writer
	io.Closer

	// SetMode sets the frame format and handshaking configuration.
	// baudrate may be freely chosen, the driver is allowed to reject
	// unachievable baud rates. databits may be any number of data bits
	// supported by the driver. parity is one of (N|O|E) for none, odd
	// or even parity. handshake is either NO_HANDSHAKE or
	// RTSCTS_HANDSHAKE.
	//
	// Known bug on Windows: Only NO_HANDSHAKE is supported.
	//SetMode(baudrate, databits, parity, stopbits, handshake int) error
	SetMode(mode Mode) error

	// GetMode retrieves the current mode settings.
	//
	// Known bug on OS X: GetMode only works after SetMode has been called
	// before. If not, it returns an error.
	GetMode() (Mode, error)

	// SetBreak turns on the generation of a break condition if on == true,
	// otherwise it clear the break condition.
	SetBreak(on bool) error
}

Serialport represents a serial port and offers configuration of baud rate, frame format, handshaking and read paramters as well as setting and clearing break conditions.

func Open

func Open(fn string) (SerialPort, error)

func TakeOver

func TakeOver(f *os.File) (SerialPort, error)

TakeOver accepts an open *os.File and returns a SerialPort representing the open file.

Attention: This calls the .Fd() method of the *os.File and thus renders the deadline functionality unusable. Furthermore blocked readers may remain stuck after a Close() if no data arrives.

type StringError

type StringError string

func (StringError) Error

func (se StringError) Error() string

Jump to

Keyboard shortcuts

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