serial

package module
v0.0.0-...-39762b5 Latest Latest
Warning

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

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

README

serial

Go package to handle serial port communications.

Documentation

Overview

Package serial provides a portable interface to access serial ports.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout      = errors.New("I/O operation timeout")
	ErrInvalid      = errors.New("invalid")
	ErrInvalidName  = errors.New("invalid name")
	ErrInvalidParam = errors.New("invalid parameter")
	ErrNotSupported = errors.New("not supported by OS or implementation")
	ErrUnexpected   = errors.New("unexpected response")
)

Functions

func ListPortNames

func ListPortNames() ([]string, error)

Types

type Config

type Config struct {
	BaudRate    int         // Baud rate. (Default: 9600)
	DataBits    int         // Number of data bits. Range: 5-8. (Default: 8)
	Parity      Parity      // Parity checking.
	StopBits    StopBits    // Number of stop bits.
	FlowControl FlowControl // Flow control mechanism.
}

type FlowControl

type FlowControl int
const (
	FlowControlNone    FlowControl = 0         // No flow control. (Default)
	FlowControlXonXoff FlowControl = 1 << iota // Software (XON/XOFF) flow control.
	FlowControlRtsCts                          // Hardware (RTS/CTS) flow control.
	FlowControlDtrDsr                          // Hardware (DTR/DSR) flow control.
)

Flow control used during transfering.

If no flow control is used, buffers on both sides of the connection are assumed to be large enough.

Software (XON/XOFF) flow control uses XON and XOFF character to perform flow control.

Hardware (RTS/CTS) flow control uses RTS output and CTS input signal to perform flow control.

Hardware (DTR/DSR) flow control uses DTR output and DSR input signal to perform flow control.

type Parity

type Parity int
const (
	ParityNone Parity = iota
	ParityOdd
	ParityEven
	ParityMark
	ParitySpace
)

Parity checking.

func (Parity) String

func (p Parity) String() string

type Port

type Port struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func Open

func Open(name string, c *Config) (p *Port, err error)

func (*Port) BaudRate

func (p *Port) BaudRate() (int, error)

func (*Port) Close

func (p *Port) Close() error

func (*Port) DataBits

func (p *Port) DataBits() (int, error)

func (*Port) FlowControl

func (p *Port) FlowControl() FlowControl

func (*Port) Flush

func (p *Port) Flush() error

Flush discards data written to the port but not transmitted, or data received but not read.

func (*Port) Parity

func (p *Port) Parity() (Parity, error)

func (*Port) Read

func (p *Port) Read(buf []byte) (int, error)

func (*Port) SetBaudRate

func (p *Port) SetBaudRate(baudrate int) error

func (*Port) SetDataBits

func (p *Port) SetDataBits(databits int) error

func (*Port) SetFlowControl

func (p *Port) SetFlowControl(flowcontrol FlowControl) error

func (*Port) SetParity

func (p *Port) SetParity(parity Parity) error

func (*Port) SetStopBits

func (p *Port) SetStopBits(stopbits StopBits) error

func (*Port) SetTimeout

func (p *Port) SetTimeout(timeout_ms_firstbyte, timeout_ms_interbyte int) error

func (*Port) StopBits

func (p *Port) StopBits() (StopBits, error)

func (*Port) Write

func (p *Port) Write(buf []byte) (int, error)

type StopBits

type StopBits int
const (
	StopBitsOne StopBits = iota
	StopBitsOnePointFive
	StopBitsTwo
)

Number of stop bits.

func (StopBits) String

func (s StopBits) String() string

Jump to

Keyboard shortcuts

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