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
- type Error
- type Options
- type ParityMode
- type Port
- func (p *Port) BytesAvailable() (int, error)
- func (p *Port) Close() error
- func (p *Port) GetCTS() (bool, error)
- func (p *Port) GetDSR() (bool, error)
- func (p *Port) GetDTR() (bool, error)
- func (p *Port) GetRTS() (bool, error)
- func (p *Port) Read(b []byte) (n int, err error)
- func (p *Port) SetDTR(level bool) error
- func (p *Port) SetRTS(level bool) error
- func (p *Port) String() string
- func (p *Port) Write(b []byte) (n int, err error)
Constants ¶
const ( PARITY_NONE = ParityMode(0) PARITY_ODD = ParityMode(1) PARITY_EVEN = ParityMode(2) )
Parity modes
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 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 ¶
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 ¶
BytesAvailable returns the number of bytes available in the serial port input buffer. Read() will block as long as there are no bytes available.