Documentation
¶
Overview ¶
Package scale implements the logic for reading weight data from a serial-connected scale.
Index ¶
Constants ¶
View Source
const ( // RetryDelay is the delay between connection retry attempts. RetryDelay = 3 * time.Second // SerialReadTimeout is the timeout for serial port reads. SerialReadTimeout = 5 * time.Second // BaudRate is the baud rate for serial communication. BaudRate = 9600 )
Communication constants for the scale reader
View Source
const ( // ErrEOF is the error code for end-of-file received. ErrEOF = "ERR_EOF" // ErrTimeout is the error code for read timeout. ErrTimeout = "ERR_TIMEOUT" // ErrRead is the error code for read error. ErrRead = "ERR_READ" // ErrConnection is the error code for connection failure. ErrConnection = "ERR_SCALE_CONN" )
Error codes for scale communication failures
Variables ¶
View Source
var BrandCommands = map[string]string{
"rhino": "P",
"rhino bar 8rs": "P",
}
BrandCommands maps scale brands to their weight request commands
View Source
var ErrorDescriptions = map[string]string{ ErrEOF: "EOF recibido. Posible desconexión.", ErrTimeout: "Timeout de lectura.", ErrRead: "Error de lectura.", ErrConnection: "No se pudo conectar al puerto serial.", }
ErrorDescriptions maps error codes to human-readable descriptions
Functions ¶
func GenerateSimulatedWeights ¶
func GenerateSimulatedWeights() []float64
GenerateSimulatedWeights creates a sequence of realistic weight readings Returns 5 fluctuating values followed by a stable reading
func GetCommand ¶
GetCommand returns the command for a given brand Defaults to "P" if brand is unknown
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader manages serial port communication with the scale
func (*Reader) ClosePort ¶
func (r *Reader) ClosePort()
ClosePort closes the serial port for config changes
Click to show internal directories.
Click to hide internal directories.