Skip to main content

Getting started

A ModDef document describes a device's Modbus register map: types, byte order, scaling, sentinels, write rules, and the semantic measurand each point reports. Every ModDef runtime reads the same document and decodes it identically.

This page reads one point, pv1_voltage, from a Growatt SPH inverter over Modbus TCP. Swap in your own transport details as needed.

Install

go get github.com/ModDefOrg/moddef/go

Read a point

doc, _ := moddef.Load("growatt-sph.moddef.yaml")
dev, _ := client.New(doc, "growatt-sph", transport) // your modbus.Transport
v, _ := dev.ReadPoint(ctx, "pv1_voltage")
fmt.Println(v) // 230.5

The runtime read the raw register 2305, applied the point's scale of 1/10, and gave you 230.5. You never wrote the offset 3 or the divisor 10 in your code; they live in the document.

Next steps