pyModbusTCP acc64 SUnSpec

726 Views Asked by At

I am trying to read values from an inverter (for solarpanels). The inverter uses Modbus (TCP/IP) with SunSpec protocol.

I am using pyModbusTCP and I can connect to the inverter and get values of type int16 and uint16 but not string or acc64. I am using this code to get the values:

from pyModbusTCP.client import ModbusClient
client = ModbusClient(host="192.168.40.10", port=502)
client.open()
client.read_holding_registers(40084)

Do I need to import something else to be able to read these values? I am pretty new to python and it is the first time I have worked with pyModbusTCP.

PDF with some SunSpec info: https://sunspec.org/wp-content/uploads/2015/06/SunSpec-Information-Models-12041.pdf

2

There are 2 best solutions below

0
On

First of all be sure register 40084 holds the value your're looking for. We're using a rev. 4 SunSpec protocol and AC Lifetime active (real) energy output in stored in an acc64 registrer at 40187 address. Anyway, in order to read an acc64 values you must read 4 values of 16 bit each:

client.read_holding_registers(40084,4).

you'll get back 4 values like:

0
0
869
55690

each of these needs now be converted back to HEX, concat togheter and then convert to int back again:

0 (dec) --> 00 00 (Hex)
0 (dec) --> 00 00 (Hex)
869 (dec) --> 03 65 (Hex)
55690 (dec) --> D9 8A (Hex)

Final HEX Value will be: 00 00 00 00 03 65 D9 8A which converted in DEC is 57.006.474

1
On

In the official documentation of pyModbusTCP: https://pymodbustcp.readthedocs.io/en/latest/package/class_ModbusClient.html we can see next description: read_holding_registers(reg_addr, reg_nb=1)

Modbus function READ_HOLDING_REGISTERS (0x03)

Parameters:

reg_addr (int) – register address (0 to 65535)

reg_nb (int) – number of registers to read (1 to 125)

Returns:
registers list or None if fail

Return type:
list of int or None

Return type is list, so we can do:

values = client.read_holding_registers(40084)
if values:
    for value in values:
        # you can convert int to string
        converted_value = str(value)
        # implement here you own lgorithm