Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Port string
Addr byte // device address (1-14), default 4
Timeout time.Duration // per-command read timeout, default 2s
}
Config holds serial port parameters for one PITEC device.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection wraps a Transport opened to a PITEC device.
func NewConnection ¶
NewConnection wraps any Transport (serial port, RFCOMM socket) in a Connection. Takes ownership of t: it is closed on error and by Close.
func Open ¶
func Open(cfg Config) (*Connection, error)
Open opens the serial port in cfg and wraps it in a Connection.
func (*Connection) Close ¶
func (c *Connection) Close() error
Close closes the underlying transport.
func (*Connection) Flush ¶
func (c *Connection) Flush()
Flush discards any bytes waiting in the read buffer.
func (*Connection) ReadFrame ¶
func (c *Connection) ReadFrame() ([]byte, error)
ReadFrame reads bytes until a complete frame (ending in CR LF or CR) is received. A read that returns no data means the transport timeout expired; any buffered partial frame is returned as-is, otherwise an error.
func (*Connection) Send ¶
func (c *Connection) Send(cmdBase byte) error
Send writes a single command byte to the device.
type Device ¶
type Device struct {
Last *protocol.Frame
Updated time.Time
// contains filtered or unexported fields
}
Device represents a connected PITEC BIOREF-19 L chamber.
func NewDevice ¶
func NewDevice(conn *Connection) *Device
NewDevice wraps an open Connection in a Device.
func (*Device) DownloadHistory ¶
DownloadHistory reads all memory records from the device using the dialog protocol. progress is called with (received, total-estimate) after each record; pass nil to ignore. Returns all frames in chronological order.
func (*Device) GetCurrent ¶
func (d *Device) GetCurrent() (*protocol.FrameCurrent, error)
GetCurrent sends the async current-values command and returns the parsed frame. The device responds with its latest 2-minute average.
type Transport ¶
type Transport interface {
io.ReadWriteCloser
SetReadTimeout(time.Duration) error
}
Transport is a bidirectional byte stream to a PITEC device. Read must return (0, nil) when the configured read timeout expires with no data, matching go.bug.st/serial semantics. RFCOMM sockets on Linux wrap their timeout errors to follow the same convention.
func OpenSerial ¶
OpenSerial opens the named serial port at 9600 baud 8N1 (PITEC standard).