Documentation
¶
Overview ¶
Package comlynx implements the Danfoss ComLynx RS485 protocol used by TripleLynx TLX PV inverters. The protocol is PPP-style HDLC framing (RFC 1662) carrying Embedded CAN Kingdom parameter messages.
The initial framing details (captured frame layout and byte-level examples) were ported from https://github.com/AMajland/Danfoss-TLX.
Index ¶
Constants ¶
const ( ParamTotalEnergy uint16 = 0x0102 // lifetime production, raw value in Wh ParamGridPowerTotal uint16 = 0x0246 // W ParamGridPowerL1 uint16 = 0x0242 // W ParamGridPowerL2 uint16 = 0x0243 // W ParamGridPowerL3 uint16 = 0x0244 // W ParamGridVoltageL1 uint16 = 0x023c // V * 10 ParamGridVoltageL2 uint16 = 0x023d // V * 10 ParamGridVoltageL3 uint16 = 0x023e // V * 10 ParamGridCurrentL1 uint16 = 0x023f // A * 1000 (mA) ParamGridCurrentL2 uint16 = 0x0240 // A * 1000 (mA) ParamGridCurrentL3 uint16 = 0x0241 // A * 1000 (mA) ParamOperatingMode uint16 = 0x0a02 // enum (0-9=off, 10-49=boot, 50-59=connecting, 60-69=on-grid, 70-79=failsafe, 80-89=off-comm) )
TLX parameter IDs. Sourced from AMajland/Danfoss-TLX (confirmed on TLX 6/8/ 10/12.5/15 kW hardware) and cross-checked against yvesf/pycomlynx.
const DefaultBaudrate = 19200
DefaultBaudrate is the RS485 baud rate used by all TLX variants.
const DefaultRetries = 2
DefaultRetries is the number of attempts before returning an error.
const DefaultTimeout = 2 * time.Second
DefaultTimeout is the per-request timeout applied to each read.
Variables ¶
var Broadcast = Address{Network: 0x0f, Subnet: 0x0f, Node: 0xff}
Broadcast is the ComLynx broadcast address. Any ComLynx node replies to a request targeted at it.
var DefaultSource = Address{Network: 0x00, Subnet: 0x00, Node: 0x02}
DefaultSource is the source address evcc advertises on the bus. Matches the hard-coded value used by AMajland/Danfoss-TLX, known to be accepted by TLX inverters.
Functions ¶
This section is empty.
Types ¶
type Address ¶
Address is a 2-byte ComLynx node address. Network and subnet fit into the first byte (4 bits each); node occupies the second byte.
func Discover ¶
Discover sends a broadcast PingRequest and returns the address of the inverter on the bus. If exactly one inverter replies it is returned. If multiple inverters reply an error is returned instructing the caller to set the node address explicitly in the configuration (one meter entry per inverter).
func NewAddress ¶
NewAddress constructs an Address. It panics on out-of-range inputs because those only come from hard-coded constants or config validation.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a single-inverter ComLynx client. All methods are safe for concurrent use.
func New ¶
New opens a connection and returns a ready Client. log may be nil for silent operation. The caller may override the destination address via SetDestination before the first read.
func (*Client) Destination ¶
Destination returns the currently configured inverter address.
func (*Client) Ping ¶
Ping issues a broadcast PingRequest and returns the source address of the first replying node, or every replying node if multi is true. Used by address discovery.
func (*Client) Read ¶
Read queries a single TLX parameter by its 16-bit ID and returns the raw 32-bit value (little-endian, as reported by the inverter). Scaling into engineering units happens at the meter wrapper layer.
func (*Client) SetDestination ¶
SetDestination updates the inverter address used by subsequent reads.
type Config ¶
type Config struct {
// Device is the local serial port (e.g. /dev/ttyUSB0). Mutually
// exclusive with URI.
Device string
// URI is a TCP endpoint exposing a raw RS485 bridge (host:port). Mutually
// exclusive with Device.
URI string
// Baudrate defaults to 19200 when unset.
Baudrate int
// Timeout is the per-request timeout. Zero uses DefaultTimeout.
Timeout time.Duration
// Retries is the number of attempts. Zero uses DefaultRetries.
Retries int
// Source is the address advertised on the bus. Zero-value uses
// DefaultSource.
Source Address
// Destination is the address of the inverter to query. Zero-value is
// interpreted as "unset"; the caller is expected to run address
// discovery before the first read.
Destination Address
}
Config holds the parameters needed to open a ComLynx client.