Documentation
¶
Index ¶
- func ParseUri(uri string) (string, *serial.Mode, error)
- type Connection
- func (c *Connection) Cancel()
- func (c *Connection) CancelRecv()
- func (c *Connection) CancelSend()
- func (c *Connection) Close()
- func (c *Connection) IsOpened() bool
- func (c *Connection) Open(timeout float64) error
- func (c *Connection) Parent() comm.Listener
- func (c *Connection) Recv(timeout float64) ([]byte, error)
- func (c *Connection) RecvFrom(timeout float64) ([]byte, any, error)
- func (c *Connection) Send(data []byte, timeout float64) error
- func (c *Connection) SendTo(data []byte, _ any, timeout float64) error
- func (c *Connection) SerialPort() serial.Port
- func (c *Connection) SetMode(mode string) error
- func (c *Connection) String() string
- func (c *Connection) Type() string
- func (c *Connection) Uri() string
- type Listener
- func (l *Listener) IsActive() bool
- func (l *Listener) SerialPort() serial.Port
- func (l *Listener) SetConnHandler(handler func(comm.Connection))
- func (l *Listener) Start() error
- func (l *Listener) Stop()
- func (l *Listener) String() string
- func (l *Listener) Type() string
- func (l *Listener) Uri() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseUri ¶
ParseUri parses a serial URI.
The expected URI format is `serial@<port>:<baud>:<mode>` <port> serial port name (e.g., /dev/ttyS0 or COM1) <baud> Baud rate (e.g., 4800,9600,19200,115200...) <mode> bytesize, parity and stopbits {8|7}{N|E|O|M|S}{1|2} example: - serial@/dev/ttyS0:9600:8N1 (linux) - serial@COM1:9600:8N1 (windows)
Returns the serial params and any error encountered.
Types ¶
type Connection ¶
type Connection struct { // Log is the logger instance for communication data logging. Log *logging.Logger // PollConfig defines the read polling. PollConfig *comm.PollingConfig // contains filtered or unexported fields }
Connection represents a serial connection with event support and logging.
func NewConnection ¶
NewConnection creates and initializes a new Connection for the given URI.
The parsed options are:
- Polling Options: detailed in comm.ParsePollingConfig
func (*Connection) Cancel ¶
func (c *Connection) Cancel()
Cancel cancels any ongoing operations on the connection.
func (*Connection) CancelRecv ¶
func (c *Connection) CancelRecv()
Cancel interrupts the ongoing receiving operation for this Connection.
func (*Connection) CancelSend ¶
func (c *Connection) CancelSend()
Cancel interrupts the ongoing sending operation for this Connection.
func (*Connection) Close ¶
func (c *Connection) Close()
Close shuts down the connection and cleaning up resources.
func (*Connection) IsOpened ¶
func (c *Connection) IsOpened() bool
IsOpened indicates whether the connection is currently open and active.
func (*Connection) Open ¶
func (c *Connection) Open(timeout float64) error
Open opens the serial port.
func (*Connection) Parent ¶
func (c *Connection) Parent() comm.Listener
Parent returns the parent Listener if any is associated with the Connection.
func (*Connection) Recv ¶
func (c *Connection) Recv(timeout float64) ([]byte, error)
Recv waits for incoming data over the connection until a timeout or interrupt event occurs. Setting timeout=0 will wait indefinitely.
func (*Connection) RecvFrom ¶
func (c *Connection) RecvFrom(timeout float64) ([]byte, any, error)
RecvFrom waits for incoming data from addr over the connection until a timeout or interrupt event occurs.
Setting timeout 0 or negative value will wait indefinitely.
func (*Connection) Send ¶
func (c *Connection) Send(data []byte, timeout float64) error
Send transmits data over the connection, with a specified timeout.
func (*Connection) SendTo ¶
func (c *Connection) SendTo(data []byte, _ any, timeout float64) error
SendTo transmits data to addr over the connection, with a specified timeout.
Setting timeout 0 or negative value will wait indefinitely.
func (*Connection) SerialPort ¶
func (c *Connection) SerialPort() serial.Port
SerialPort returns the underlying serial port object
func (*Connection) SetMode ¶
func (c *Connection) SetMode(mode string) error
Mode sets new mode for the serial port. mode has the format `<baud>:<mode>` as defined for the URI.
func (*Connection) String ¶
func (c *Connection) String() string
String returns a string representation of the Connection.
func (*Connection) Type ¶
func (c *Connection) Type() string
Type returns the type of the connection as inferred from the Uri.
type Listener ¶
type Listener struct { // ConnectionHandler defines the function to handle incoming connections. ConnectionHandler func(comm.Connection) // Log is the logger instance for communication data logging. Log *logging.Logger // PollConfig defines the read polling. PollConfig *comm.PollingConfig // contains filtered or unexported fields }
Listener represents a serial listener that handles incoming connections
func NewListener ¶
NewListener creates a new Listener.
The parsed options are:
- Polling Options: detailed in comm.ParsePollingConfig
func (*Listener) SerialPort ¶
SerialPort returns the underlying serial port object
func (*Listener) SetConnHandler ¶
func (l *Listener) SetConnHandler(handler func(comm.Connection))
SetConnHandler sets a callback function to handle connections.
func (*Listener) Start ¶
Start begins listening for connections, calling the connectionHandler for each established connection.