rs232

package
v0.0.0-...-ee07738 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package rs232 offers RS-232 serial port communication functionality. The serial port is set to raw mode, no flow control. Read timeouts are supported, as well as full access to the RTS/CTS DTR/DSR control signals.

rs232 implements the io.ReadWriteCloser interface. Read() and Write() are blocking operations that can be performed simultaneously from different goroutines.

Control signals:

  • RTS (Request To Send) output : data is ready to be sent.

  • CTS (Clear To Send) input : ready to receive data.

  • DTR (Data Terminal Ready) output : ready for communication.

  • DSR (Data Set Ready) input : ready to receive data.

Supported OS: Linux, OS X. This package does not depend on CGO.

TODO: setting the timeout at any time?

Index

Constants

View Source
const (
	PARITY_NONE = ParityMode(0)
	PARITY_ODD  = ParityMode(1)
	PARITY_EVEN = ParityMode(2)
)

Parity modes

View Source
const (
	ERR_NONE   = 0 // no error
	ERR_DEVICE = 1 // device error
	ERR_ACCESS = 2 // no access permissions
	ERR_PARAMS = 3 // invalid parameters
)

rs232 error codes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code int
	Msg  string
}

Error holds an error code and the corresponding human-readable message.

func (*Error) Error

func (e *Error) Error() string

Error implements the built-in error interface.

type Options

type Options struct {
	BitRate  uint32     // number of bits per second (baud)
	DataBits uint8      // number of data bits (5, 6, 7, 8)
	StopBits uint8      // number of stop bits (1, 2)
	Parity   ParityMode // none, odd, even
	Timeout  uint8      // read timeout in units of 0.1 seconds (0 = disable)
}

Serial port options.

Valid bit rates (linux): 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000.

Valid bit rates (OS X): 200, 300, 600, 1200, 1800, 2400, 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 78600, 115200, 230400

type ParityMode

type ParityMode uint8

type Port

type Port struct {
	// contains filtered or unexported fields
}

func Open

func Open(name string, opt Options) (port *Port, err error)

Open will open the named serial port device with the given options. Open returns an *rs232.Error which implements the built-in error interface but additionally allows access to specific error codes. See Error.

See type Options for valid parameter ranges.

func (*Port) BytesAvailable

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

BytesAvailable returns the number of bytes available in the serial port input buffer. Read() will block as long as there are no bytes available.

func (*Port) Close

func (p *Port) Close() error

func (*Port) GetCTS

func (p *Port) GetCTS() (bool, error)

GetCTS gets the 'Clear To Send' control signal level.

func (*Port) GetDSR

func (p *Port) GetDSR() (bool, error)

GetDSR gets the 'Data Set Ready' control signal level.

func (*Port) GetDTR

func (p *Port) GetDTR() (bool, error)

GetDTR gets the 'Data Terminal Ready' control signal level.

func (*Port) GetRTS

func (p *Port) GetRTS() (bool, error)

GetRTS gets the 'Request To Send' control signal level.

func (*Port) Read

func (p *Port) Read(b []byte) (n int, err error)

func (*Port) SetDTR

func (p *Port) SetDTR(level bool) error

SetDTR sets the 'Data Terminal Ready' control signal level.

func (*Port) SetRTS

func (p *Port) SetRTS(level bool) error

SetRTS sets the 'Request To Send' control signal level.

func (*Port) String

func (p *Port) String() string

func (*Port) Write

func (p *Port) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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