Ah got it.
The bare minimum you need is more or less this:
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
inv = ModbusClient(method='rtu', port='/dev/ttyUSB0', baudrate=9600, stopbits=1,
parity='N', bytesize=8, timeout=1)
inv.connect()
rr = inv.read_input_registers(0, 45, unit='0x1')
print rr
First you import the modbus library, define the modbus interface (inv) and do inv.connect()
, this last command will open the serial port on Linux (/dev/ttyUSB0
) in this example. If everything ok until here, you can issue any number of read_input_registers
or read_holding_registers
and print out whatever you want. In the example above, I am reading 45 registers starting from 0 (or register from 0 to 44). As per Growatt documentation, inverter can read at most 45 register in a single command, and also, it cannot return registers like from 10 to 54 because 10~44 are in on “45 registers page” and 45~54 are stored in another “45 registers page”. This is most likely due internal memory organization. Hence, you can read 0-44, 10-15, 40-44, 45-89 but you cannot read 40-60, 70-110, etc.
Also, notice that there are two classes of register a Growatt would know, the input registers are read using function read_input_registers
and holding registers that are read with read_holding_registers
. Simply put, a input register is a quantity that a device give you, a temperature sensor would have a input register that stores current temperature from the sensor. A holding register is more likely a configuration hence, a temperature device would have a holding register to configure readings as Celsius or Fahrenheit. Growatt has holding registers for every configuration like max voltage, timers, faults, etc. and reading registers for power, energy, vdc, vac, etc… Example: firmware version is a holding register while current out power is a reading register.
Hope this helps