Documentation
¶
Overview ¶
sio.Port - serial port (like /dev/ttyUSB0) abstraction * sio.Console - simple terminal bound to an open sio.Port and /dev/tty
Copyright (C) jno, 2019 Support for select(2) via syscall.Select() See also: Ioctl.Fd*() methods
Index ¶
- Constants
- Variables
- func DeviceClassName(class uint64) string
- func GetDeviceNumber(st os.FileInfo) (major, minor uint64)
- func GetRDev(st os.FileInfo) uint64
- func IsValidCharSize(v int) bool
- func IsValidParity(v int) bool
- func IsValidSpeed(v uint32) bool
- func IsValidStopBits(v int) bool
- func PrintLocations(locations []string, printf func(string, ...interface{}) (int, error))
- func WrapError(err interface{}) *errors.Error
- type BitRate
- type CharSize
- type CommandChannel
- type Console
- type DeviceClassMapper
- type Ioctl
- func (fd *Ioctl) FdClr(set *syscall.FdSet)
- func (fd *Ioctl) FdIsSet(set *syscall.FdSet) bool
- func (fd *Ioctl) FdSet(set *syscall.FdSet)
- func (fd *Ioctl) Flock(how int) (e error)
- func (fd *Ioctl) GETFL() (flags uintptr, e error)
- func (fd *Ioctl) InWaiting() (cnt uint32, e error)
- func (fd *Ioctl) NonBlock(set bool) (e error)
- func (fd *Ioctl) OutWaiting() (cnt uint32, e error)
- func (fd *Ioctl) Reconfigure(termios *syscall.Termios, port *Port) (e error)
- func (fd *Ioctl) SendBreak() (e error)
- func (fd *Ioctl) Set(value uintptr)
- func (fd *Ioctl) SetDTR(set bool) (e error)
- func (fd *Ioctl) SetRTS(set bool) (e error)
- func (fd *Ioctl) SetRs485(rs485 Rs485) (e error)
- func (fd *Ioctl) TIOCGRS485(buf *[8]uint32) (e error)
- func (fd *Ioctl) TIOCINQ() (count uint32, e error)
- func (fd *Ioctl) TIOCMGET() (tiocm uint32, e error)
- func (fd *Ioctl) TIOCOUTQ() (count uint32, e error)
- func (fd *Ioctl) TIOCSRS485(buf [8]uint32) (e error)
- func (fd *Ioctl) TcDrain() (e error)
- func (fd *Ioctl) TcFlow(act int) (e error)
- func (fd *Ioctl) TcFlush(qsel int) (e error)
- func (fd *Ioctl) TcGetAttr() (termios syscall.Termios, e error)
- func (fd *Ioctl) TcSetAttr(termios syscall.Termios) (e error)
- type Parity
- type Port
- func (self *Port) CD() bool
- func (self *Port) CTS() bool
- func (self *Port) Close() error
- func (self *Port) DSR() bool
- func (self *Port) DeviceClassName() string
- func (self *Port) DeviceId() (major, minor uint64)
- func (self *Port) Drain() (e error)
- func (self *Port) InWaiting() (n uint32, e error)
- func (self *Port) Interact(cc CommandChannel, write2other func([]byte) error)
- func (self *Port) IsOpen() bool
- func (self *Port) Open(path string) (e error)
- func (self *Port) RI() bool
- func (self *Port) Read(data []byte) (n int, e error)
- func (self *Port) ReadLine() (s string, e error)
- func (self *Port) ReadUntil(ends []string) (s string, e error)
- func (self *Port) ResetInput() (e error)
- func (self *Port) ResetOutput() (e error)
- func (self *Port) SendBreak() (e error)
- func (self *Port) SetDeadline(t time.Time) (e error)
- func (self *Port) SetInputFlowControl(set bool) (e error)
- func (self *Port) SetOutputFlowControl(set bool) (e error)
- func (self *Port) String() string
- func (self *Port) SysFS() []string
- func (self *Port) TIOCMGET_bit(bit uint32) bool
- func (self *Port) Write(data []byte) (n int, e error)
- func (self *Port) WriteLine(s string) (e error)
- type PortError
- type Rs485
- type StopBits
- type SysFS
Constants ¶
View Source
const ( TCOOFF = 0 TCOON = 1 TCIOFF = 2 TCION = 3 )
View Source
const ( SER_RS485_ENABLED = 0x01 SER_RS485_RTS_ON_SEND = 0x02 SER_RS485_RTS_AFTER_SEND = 0x04 SER_RS485_RX_DURING_TX = 0x10 )
View Source
const ( CHAR_SIZE_5 = CharSize(5) CHAR_SIZE_6 = CharSize(6) CHAR_SIZE_7 = CharSize(7) CHAR_SIZE_8 = CharSize(8) )
View Source
const ( PARITY_NONE = Parity(0) PARITY_ODD = Parity(1) PARITY_EVEN = Parity(2) PARITY_MARK = Parity(3) PARITY_SPACE = Parity(4) )
View Source
const ( STOP_BITS_1 = StopBits(1) STOP_BITS_2 = StopBits(2) )
View Source
const ( BIT_RATE_B0 = BitRate(syscall.B0) BIT_RATE_B50 = BitRate(syscall.B50) BIT_RATE_B75 = BitRate(syscall.B75) BIT_RATE_B110 = BitRate(syscall.B110) BIT_RATE_B134 = BitRate(syscall.B134) BIT_RATE_B150 = BitRate(syscall.B150) BIT_RATE_B200 = BitRate(syscall.B200) BIT_RATE_B300 = BitRate(syscall.B300) BIT_RATE_B600 = BitRate(syscall.B600) BIT_RATE_B1200 = BitRate(syscall.B1200) BIT_RATE_B1800 = BitRate(syscall.B1800) BIT_RATE_B2400 = BitRate(syscall.B2400) BIT_RATE_B4800 = BitRate(syscall.B4800) BIT_RATE_B9600 = BitRate(syscall.B9600) BIT_RATE_B19200 = BitRate(syscall.B19200) BIT_RATE_B38400 = BitRate(syscall.B38400) BIT_RATE_B57600 = BitRate(syscall.B57600) BIT_RATE_B115200 = BitRate(syscall.B115200) BIT_RATE_B230400 = BitRate(syscall.B230400) BIT_RATE_B460800 = BitRate(syscall.B460800) BIT_RATE_B500000 = BitRate(syscall.B500000) BIT_RATE_B576000 = BitRate(syscall.B576000) BIT_RATE_B921600 = BitRate(syscall.B921600) BIT_RATE_B1000000 = BitRate(syscall.B1000000) BIT_RATE_B1152000 = BitRate(syscall.B1152000) BIT_RATE_B1500000 = BitRate(syscall.B1500000) BIT_RATE_B2000000 = BitRate(syscall.B2000000) BIT_RATE_B2500000 = BitRate(syscall.B2500000) BIT_RATE_B3000000 = BitRate(syscall.B3000000) BIT_RATE_B3500000 = BitRate(syscall.B3500000) BIT_RATE_B4000000 = BitRate(syscall.B4000000) )
View Source
const ASYNC_LOW_LATENCY uint32 = 0x2000
View Source
const CMSPAR uint32 = 010000000000 // linux, octal!
View Source
const CRTSCTS uint32 = 020000000000 /* flow control */
View Source
const CharacterSpecialDeviceMode = os.ModeDevice | os.ModeCharDevice
View Source
const DefaultTimeout = time.Millisecond * 50 // 0.05 sec
View Source
const E_OK = syscall.Errno(0)
View Source
const NoSelectTimeout float64 = -1. // will cause timeout pointer to be nil
View Source
const PortOpenFlags = os.O_RDWR | syscall.O_NOCTTY | syscall.O_NONBLOCK
View Source
const ProcDevices = "/proc/devices"
View Source
const ProcMisc = "/proc/misc"
Character devices:
1 mem 4 tty 5 /dev/tty 5 /dev/console ...
251 dimmctl 252 ndctl 253 tpm 254 gpiochip
Block devices:
7 loop 8 sd 9 md 11 sr 65 sd ...
253 device-mapper 254 mdp 259 blkext
View Source
const Prompt = ""
View Source
const SysfsClass = "tty"
View Source
const SysfsRoot = "/sys"
View Source
const TTY = "/dev/tty"
View Source
const UERROR = uintptr(18446744073709551615)
View Source
const ZeroIoctl = Ioctl(0)
Variables ¶
View Source
var AutoLoad = []string{ ProcDevices, ProcMisc, }
234 btrfs-control 232 kvm 235 autofs
56 memory_bandwidth 57 network_throughput 58 network_latency 59 cpu_dma_latency
184 microcode 227 mcelog 236 device-mapper 223 uinput
1 psaux
200 tun 237 loop-control
60 lightnvm
183 hw_random 228 hpet 229 fuse
61 ecryptfs
231 snapshot
62 rfkill 63 vga_arbiter
View Source
var PortNotOpenError = NewPortError("Port was not open")
View Source
var PortTimeoutError = NewPortError("Port timed out")
View Source
var Stops = []string{
"\r\nOK\r\n",
"\r\nERROR\r\n",
}
View Source
var SysCharSize = map[CharSize]uint32{ CHAR_SIZE_5: syscall.CS5, CHAR_SIZE_6: syscall.CS6, CHAR_SIZE_7: syscall.CS7, CHAR_SIZE_8: syscall.CS8, }
View Source
var ZeroFdSet = syscall.FdSet{ Bits: [16]int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }
Functions ¶
func DeviceClassName ¶
func GetDeviceNumber ¶
func IsValidCharSize ¶
func IsValidParity ¶
func IsValidSpeed ¶
func IsValidStopBits ¶
func PrintLocations ¶
Types ¶
type CommandChannel ¶
type CommandChannel chan []byte
func (*CommandChannel) SendString ¶
func (self *CommandChannel) SendString(s string)
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
func NewConsole ¶
func (*Console) WriteString ¶
type DeviceClassMapper ¶
func NewDeviceClassMapper ¶
func NewDeviceClassMapper() *DeviceClassMapper
func (*DeviceClassMapper) GetName ¶
func (self *DeviceClassMapper) GetName(class uint64) (name string)
func (*DeviceClassMapper) Load ¶
func (self *DeviceClassMapper) Load()
type Ioctl ¶
type Ioctl uintptr
func (*Ioctl) OutWaiting ¶
func (*Ioctl) Reconfigure ¶
func (*Ioctl) TIOCGRS485 ¶
func (*Ioctl) TIOCSRS485 ¶
type Port ¶
type Port struct {
// contains filtered or unexported fields
}
func NewSerialPort ¶
NewSerialPort("/dev/ttyUSB0") returns ref to an open Port instance
func (*Port) DeviceClassName ¶
func (*Port) Interact ¶
func (self *Port) Interact(cc CommandChannel, write2other func([]byte) error)
Use as: `go port.Interact(commandChan, tty.Write)` Close the port to terminate.
func (*Port) ResetInput ¶
func (*Port) ResetOutput ¶
func (*Port) SetInputFlowControl ¶
func (*Port) SetOutputFlowControl ¶
func (*Port) TIOCMGET_bit ¶
type PortError ¶
type PortError struct {
// contains filtered or unexported fields
}
func NewPortError ¶
Click to show internal directories.
Click to hide internal directories.