sio

package module
v0.0.0-...-cdf46f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 16 Imported by: 0

README

go-serial

Serial port control for Go. Sorta clone of PySerial

INCOMPLETE! WORK IN PROGRESS!

Based on:

EOF

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

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 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 DeviceClassName(class uint64) string

func GetDeviceNumber

func GetDeviceNumber(st os.FileInfo) (major, minor uint64)

func GetRDev

func GetRDev(st os.FileInfo) uint64

func IsValidCharSize

func IsValidCharSize(v int) bool

func IsValidParity

func IsValidParity(v int) bool

func IsValidSpeed

func IsValidSpeed(v uint32) bool

func IsValidStopBits

func IsValidStopBits(v int) bool

func PrintLocations

func PrintLocations(locations []string,
	printf func(string, ...interface{}) (int, error),
)

func WrapError

func WrapError(err interface{}) *errors.Error

Types

type BitRate

type BitRate uint32

type CharSize

type CharSize uint

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 NewConsole() (con *Console, e error)

func (*Console) Close

func (self *Console) Close() (e error)

func (*Console) Open

func (self *Console) Open() (e error)

func (*Console) ReadLine

func (self *Console) ReadLine() (s string, e error)

ReadLine() reads a line from user's keyboard

func (*Console) Write

func (self *Console) Write(s []byte) (e error)

Write() writes to user's screen

func (*Console) WriteString

func (self *Console) WriteString(s string) (e error)

type DeviceClassMapper

type DeviceClassMapper map[uint64][]string

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) FdClr

func (fd *Ioctl) FdClr(set *syscall.FdSet)

func (*Ioctl) FdIsSet

func (fd *Ioctl) FdIsSet(set *syscall.FdSet) bool

func (*Ioctl) FdSet

func (fd *Ioctl) FdSet(set *syscall.FdSet)

func (*Ioctl) Flock

func (fd *Ioctl) Flock(how int) (e error)

func (*Ioctl) GETFL

func (fd *Ioctl) GETFL() (flags uintptr, e error)

func (*Ioctl) InWaiting

func (fd *Ioctl) InWaiting() (cnt uint32, e error)

func (*Ioctl) NonBlock

func (fd *Ioctl) NonBlock(set bool) (e error)

func (*Ioctl) OutWaiting

func (fd *Ioctl) OutWaiting() (cnt uint32, e error)

func (*Ioctl) Reconfigure

func (fd *Ioctl) Reconfigure(termios *syscall.Termios, port *Port) (e error)

func (*Ioctl) SendBreak

func (fd *Ioctl) SendBreak() (e error)

func (*Ioctl) Set

func (fd *Ioctl) Set(value uintptr)

func (*Ioctl) SetDTR

func (fd *Ioctl) SetDTR(set bool) (e error)

func (*Ioctl) SetRTS

func (fd *Ioctl) SetRTS(set bool) (e error)

func (*Ioctl) SetRs485

func (fd *Ioctl) SetRs485(rs485 Rs485) (e error)

func (*Ioctl) TIOCGRS485

func (fd *Ioctl) TIOCGRS485(buf *[8]uint32) (e error)

func (*Ioctl) TIOCINQ

func (fd *Ioctl) TIOCINQ() (count uint32, e error)

func (*Ioctl) TIOCMGET

func (fd *Ioctl) TIOCMGET() (tiocm uint32, e error)

func (*Ioctl) TIOCOUTQ

func (fd *Ioctl) TIOCOUTQ() (count uint32, e error)

func (*Ioctl) TIOCSRS485

func (fd *Ioctl) TIOCSRS485(buf [8]uint32) (e error)

func (*Ioctl) TcDrain

func (fd *Ioctl) TcDrain() (e error)

func (*Ioctl) TcFlow

func (fd *Ioctl) TcFlow(act int) (e error)

func (*Ioctl) TcFlush

func (fd *Ioctl) TcFlush(qsel int) (e error)

func (*Ioctl) TcGetAttr

func (fd *Ioctl) TcGetAttr() (termios syscall.Termios, e error)

func (*Ioctl) TcSetAttr

func (fd *Ioctl) TcSetAttr(termios syscall.Termios) (e error)

type Parity

type Parity uint

type Port

type Port struct {
	// contains filtered or unexported fields
}

func NewSerialPort

func NewSerialPort(dev string) *Port

NewSerialPort("/dev/ttyUSB0") returns ref to an open Port instance

func (*Port) CD

func (self *Port) CD() bool

func (*Port) CTS

func (self *Port) CTS() bool

func (*Port) Close

func (self *Port) Close() error

func (*Port) DSR

func (self *Port) DSR() bool

func (*Port) DeviceClassName

func (self *Port) DeviceClassName() string

func (*Port) DeviceId

func (self *Port) DeviceId() (major, minor uint64)

func (*Port) Drain

func (self *Port) Drain() (e error)

func (*Port) InWaiting

func (self *Port) InWaiting() (n uint32, e error)

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) IsOpen

func (self *Port) IsOpen() bool

func (*Port) Open

func (self *Port) Open(path string) (e error)

func (*Port) RI

func (self *Port) RI() bool

func (*Port) Read

func (self *Port) Read(data []byte) (n int, e error)

func (*Port) ReadLine

func (self *Port) ReadLine() (s string, e error)

func (*Port) ReadUntil

func (self *Port) ReadUntil(ends []string) (s string, e error)

func (*Port) ResetInput

func (self *Port) ResetInput() (e error)

func (*Port) ResetOutput

func (self *Port) ResetOutput() (e error)

func (*Port) SendBreak

func (self *Port) SendBreak() (e error)

func (*Port) SetDeadline

func (self *Port) SetDeadline(t time.Time) (e error)

func (*Port) SetInputFlowControl

func (self *Port) SetInputFlowControl(set bool) (e error)

func (*Port) SetOutputFlowControl

func (self *Port) SetOutputFlowControl(set bool) (e error)

func (*Port) String

func (self *Port) String() string

func (*Port) SysFS

func (self *Port) SysFS() []string

func (*Port) TIOCMGET_bit

func (self *Port) TIOCMGET_bit(bit uint32) bool

func (*Port) Write

func (self *Port) Write(data []byte) (n int, e error)

func (*Port) WriteLine

func (self *Port) WriteLine(s string) (e error)

type PortError

type PortError struct {
	// contains filtered or unexported fields
}

func NewPortError

func NewPortError(message string, args ...interface{}) *PortError

func (*PortError) Error

func (self *PortError) Error() string

func (*PortError) Set

func (self *PortError) Set(e error, m string)

func (*PortError) Unwrap

func (self *PortError) Unwrap() error

type Rs485

type Rs485 struct {
	Enabled                                      bool
	Loopback                                     bool
	Rts_level_for_tx, Rts_level_for_rx           bool
	Delay_before_tx, Delay_before_rx             bool
	Delay_before_tx_value, Delay_before_rx_value float64
}

func (*Rs485) Update

func (self *Rs485) Update(buf *[8]uint32)

type StopBits

type StopBits uint

type SysFS

type SysFS uint64

func (*SysFS) Locate

func (self *SysFS) Locate(class string, major, minor uint64) []string

func (*SysFS) Use

func (self *SysFS) Use(rdev uint64)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL