Documentation
¶
Overview ¶
Package serialport allows you to easily access serial ports
Index ¶
Constants ¶
const ( BR110 = 110 // 110 bps BR300 = 300 // 300 bps BR600 = 600 // 600 bps BR1200 = 1200 // 1200 bps BR2400 = 2400 // 2400 bps BR4800 = 4800 // 4800 bps BR9600 = 9600 // 9600 bps BR14400 = 14400 // 14400 bps BR19200 = 19200 // 19200 bps BR38400 = 38400 // 38400 bps BR57600 = 57600 // 57600 bps BR115200 = 115200 // 115200 bps BR128000 = 128000 // 128000 bps BR256000 = 256000 // 256000 bps )
BaudRate
const ( DB5 = 5 // 5 data bits DB6 = 6 // 6 data bits DB7 = 7 // 7 data bits DB8 = 8 // 8 data bits )
DataBits
const ( SB1 = 1 // 1 stop bit SB1_5 = 15 // 1.5 stop bits SB2 = 2 // 2 stop bits )
StopBits
const ( PN = 0 // No parity PO = 1 // Odd parity PE = 2 // Even parity PM = 3 // Mark parity PS = 4 // Space parity )
Parity
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config for serial port configuration:
BaudRate is the baud rate of serial transmission DataBits is the number of bits per character StopBits is the number of stop bits Parity is a method of detecting errors in transmission Timeout is the serial port Read() timeout
func DefaultConfig ¶ added in v0.9.9
func DefaultConfig() Config
DefaultConfig returns a default serial port configuration:
115200 bps baudrate 8 data bits 1 stop bit no parity 100 ms timeout
type SerialPort ¶ added in v0.9.9
type SerialPort struct {
// contains filtered or unexported fields
}
A SerialPort is a serial port. This must be instantiated by calling Open() and not manually.
func Open ¶
func Open(name string, cfg Config) (sp *SerialPort, err error)
Open opens a serial port.
func (*SerialPort) Close ¶ added in v0.9.9
func (sp *SerialPort) Close() error
Close close the serial port.
func (*SerialPort) Config ¶ added in v0.9.9
func (sp *SerialPort) Config() (cfg Config, err error)
Config returns the configuration of the serial port.
func (*SerialPort) Flush ¶ added in v1.0.0
func (sp *SerialPort) Flush() error
Flush flushes both data received but not read, and data written but not transmitted.
func (*SerialPort) Read ¶ added in v0.9.9
func (sp *SerialPort) Read(b []byte) (n int, err error)
Read reads up to len(b) bytes from the serial port. It returns the number of bytes (0 <= n <= len(b)) read from the serial port and any errors encountered. Note:
Timeout < 100 ms: Read blocks until at least one byte is readable; Timeout > 100 ms: Read blocks until at least one byte is read or timeout.
func (*SerialPort) SetConfig ¶ added in v0.9.9
func (sp *SerialPort) SetConfig(cfg Config) error
SetConfig Set the serial port according to Config.