Documentation ¶
Overview ¶
Package term manages POSIX terminals. As POSIX terminals are connected to, or emulate, a UART, this package also provides control over the various UART and serial line parameters.
Index ¶
- Constants
- func CBreakMode(t *Term) error
- func FlowControl(kind int) func(*Term) error
- func RawMode(t *Term) error
- func ReadTimeout(d time.Duration) func(*Term) error
- func Speed(baud int) func(*Term) error
- type Term
- func (t *Term) Available() (int, error)
- func (t *Term) Buffered() (int, error)
- func (t *Term) Close() error
- func (t *Term) DTR() (bool, error)
- func (t *Term) Flush() error
- func (t *Term) GetParity() (int, error)
- func (t *Term) RTS() (bool, error)
- func (t *Term) Read(b []byte) (int, error)
- func (t *Term) Restore() error
- func (t *Term) SendBreak() error
- func (t *Term) SetCbreak() error
- func (t *Term) SetDTR(v bool) error
- func (t *Term) SetFlowControl(kind int) error
- func (t *Term) SetOption(options ...func(*Term) error) error
- func (t *Term) SetParity(parity int) error
- func (t *Term) SetRTS(v bool) error
- func (t *Term) SetRaw() error
- func (t *Term) SetReadTimeout(d time.Duration) error
- func (t *Term) SetRecvParityCheckOn(onIgn bool) error
- func (t *Term) SetSpeed(baud int) error
- func (t *Term) Write(b []byte) (int, error)
Examples ¶
Constants ¶
const ( NONE = iota // flow control off XONXOFF // software flow control HARDWARE // hardware flow control )
const ( //ParNONE paryty off ParNONE = iota //ParEVEN paryty ParEVEN //ParODD parity is ODD ParODD //ParMARK parity is MARK ParMARK //ParSPACE parity is SPACE ParSPACE //ParIGN parity is ParIGN ParIGN )
const CMSPAR uint32 = 0x40000000
Variables ¶
This section is empty.
Functions ¶
func FlowControl ¶
FlowControl sets the flow control option for the terminal.
func ReadTimeout ¶
ReadTimeout sets the read timeout option for the terminal.
Types ¶
type Term ¶
type Term struct {
// contains filtered or unexported fields
}
Term represents an asynchronous communications port.
func Open ¶
Open opens an asynchronous communications port.
Example ¶
Open a terminal in raw mode at 19200 baud.
Open("/dev/ttyUSB0", Speed(19200), RawMode)
Output:
func (*Term) Buffered ¶
Buffered returns the number of bytes that have been written into the current buffer.
func (*Term) Flush ¶
Flush flushes both data received but not read, and data written but not transmitted.
func (*Term) Read ¶
Read reads up to len(b) bytes from the terminal. It returns the number of bytes read and an error, if any. EOF is signaled by a zero count with err set to io.EOF.
func (*Term) Restore ¶
Restore restores the state of the terminal captured at the point that the terminal was originally opened.
Example ¶
Restore the terminal state
t, _ := Open("/dev/tty") // mutate terminal state t.Restore()
Output:
func (*Term) SendBreak ¶
SendBreak sends a break signal.
Example ¶
Send Break to the remote DTE.
t, _ := Open("/dev/ttyUSB0") for { time.Sleep(3 * time.Second) log.Println("Break...") t.SendBreak() }
Output:
func (*Term) SetDTR ¶
SetDTR sets the DTR (data terminal ready) signal.
Example ¶
Reset an Arduino by toggling the DTR signal.
t, _ := Open("/dev/USB0") t.SetDTR(false) // toggle DTR low time.Sleep(250 * time.Millisecond) t.SetDTR(true) // raise DTR, resets Ardunio par, _ := t.GetParity() t.SetParity(par)
Output:
func (*Term) SetFlowControl ¶
SetFlowControl sets whether hardware flow control is enabled.
func (*Term) SetOption ¶
SetOption takes one or more option function and applies them in order to Term.
func (*Term) SetReadTimeout ¶
SetReadTimeout sets the read timeout. A zero value for d means read operations will not time out.
func (*Term) SetRecvParityCheckOn ¶
SetRecvParityCheckOn - parity