device

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scan

func Scan() ([]string, error)

Scan returns the list of available serial port names on this machine.

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

func NewConnection(t Transport, addr byte, timeout time.Duration) (*Connection, error)

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

func (c *Connection) Addr() byte

Addr returns the device address in use.

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

func (d *Device) DownloadHistory(progress func(n int)) ([]*protocol.Frame, error)

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

func OpenSerial(port string) (Transport, error)

OpenSerial opens the named serial port at 9600 baud 8N1 (PITEC standard).

Jump to

Keyboard shortcuts

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