olivergregorius / sun2000_modbus

Library for reading Huawei Sun2000 inverter metrics via Modbus TCP
MIT License
23 stars 9 forks source link

Step by step install, test and error #23

Closed MilanCiprian closed 1 year ago

MilanCiprian commented 1 year ago

I install python3.10 and pip3.10, then I install sun200_modbus:

> pip3.10 install sun2000_modbus
Collecting sun2000_modbus
  Downloading sun2000_modbus-2.0.0-py3-none-any.whl (12 kB)
Collecting pymodbus==2.5.3
  Using cached pymodbus-2.5.3-py2.py3-none-any.whl (154 kB)
Collecting pyserial>=3.4
  Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Collecting six>=1.15.0
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, pyserial, pymodbus, sun2000-modbus
Successfully installed pymodbus-2.5.3 pyserial-3.5 six-1.16.0 sun2000-modbus-2.0.0

Then I create the file ReadPower2.py with code:

from sun2000_modbus import inverter
from sun2000_modbus import registers

inverter = inverter.Sun2000(host='192.168.15.40')
inverter.connect()
if inverter.connected:
    input_power = inverter.read_formatted(registers.InverterEquipmentRegister.InputPower)
    print(input_power)

Then I run the code and I get this error:

> python3.10 ReadPower2.py 
INFO:root:Successfully connected to inverter
Traceback (most recent call last):
  File "/var/www/html/PFV_Sun2000/ReadPower2.py", line 6, in <module>
    if inverter.connected:
AttributeError: 'Sun2000' object has no attribute 'connected'. Did you mean: 'connect'?
olivergregorius commented 1 year ago

Hi @MilanCiprian, oh you've found a "bug" in the documentation. The code snippet should be:

from sun2000_modbus import inverter
from sun2000_modbus import registers

inverter = inverter.Sun2000(host='192.168.15.40')
inverter.connect()
if inverter.isConnected():
    input_power = inverter.read_formatted(registers.InverterEquipmentRegister.InputPower)
    print(input_power)

I will fix the documentation this evening. Please adjust your code accordingly, should be working.