import "github.com/pkg/term"
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.
term.go term_linux.go term_open_posix.go term_posix.go
const (
NONE = iota // flow control off
XONXOFF // software flow control
HARDWARE // hardware flow control
)CBreakMode places the terminal into cbreak mode.
FlowControl sets the flow control option for the terminal.
RawMode places the terminal into raw mode.
ReadTimeout sets the read timeout option for the terminal.
Speed sets the baud rate option for the terminal.
type Term struct {
// contains filtered or unexported fields
}Term represents an asynchronous communications port.
Open opens an asynchronous communications port.
Open a terminal in raw mode at 19200 baud.
Code:
Open("/dev/ttyUSB0", Speed(19200), RawMode)
Available returns how many bytes are unused in the buffer.
Buffered returns the number of bytes that have been written into the current buffer.
Close closes the device and releases any associated resources.
DTR returns the state of the DTR (data terminal ready) signal.
Flush flushes both data received but not read, and data written but not transmitted.
RTS returns the state of the RTS (data terminal ready) signal.
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.
Restore restores the state of the terminal captured at the point that the terminal was originally opened.
Restore the terminal state
Code:
t, _ := Open("/dev/tty")
// mutate terminal state
t.Restore()
SendBreak sends a break signal.
Send Break to the remote DTE.
Code:
t, _ := Open("/dev/ttyUSB0")
for {
time.Sleep(3 * time.Second)
log.Println("Break...")
t.SendBreak()
}
SetCbreak sets cbreak mode.
SetDTR sets the DTR (data terminal ready) signal.
Reset an Arduino by toggling the DTR signal.
Code:
t, _ := Open("/dev/USB0")
t.SetDTR(false) // toggle DTR low
time.Sleep(250 * time.Millisecond)
t.SetDTR(true) // raise DTR, resets Ardunio
SetFlowControl sets whether hardware flow control is enabled.
SetOption takes one or more option function and applies them in order to Term.
SetRTS sets the RTS (data terminal ready) signal.
SetRaw sets raw mode.
SetReadTimeout sets the read timeout. A zero value for d means read operations will not time out.
SetSpeed sets the receive and transmit baud rates.
Write writes len(b) bytes to the terminal. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).
| Path | Synopsis |
|---|---|
| termios | Package termios implements the low level termios(3) terminal line discipline facilities. |
Package term imports 6 packages (graph) and is imported by 43 packages. Updated 2018-07-30. Refresh now. Tools for package owners.