Skip to content

Commit

Permalink
Add individual port
Browse files Browse the repository at this point in the history
  • Loading branch information
steff393 committed Jun 3, 2023
1 parent cdf0ceb commit 57f1d72
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
64 changes: 56 additions & 8 deletions cfg.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
[Section 1]
[Configuration]
cfgInverterIp = 192.168.178.94
cfgInverterPort = 502
cfgInverterAddr = 1
cfgInverterType = 1
Typ = test

[Section 2]
register = 40206
registerCount = 5
# -------------------------------------

[Register]
# Beispiel: Lese 5 Register ab 30810
[test]
# Beispiel: Lese 5 Register ab 30810, dann 1 Register aus 60820 und 1 Register aus 30822
Port = 502
30810 = 5
60820 = 1
30822 = 1

[SolarEdge]
# "cfgInverterType":1
Port = 1502
40071 = 1 # I_AC_Current
40083 = 2 # AC Power value + AC Power scale factor
40206 = 1 # Total Real Power (sum of active phases)
40210 = 1 # AC Real Power Scale Factor

[Fronius]
# "cfgInverterType":2
# SlaveID=240
Port = 502
40083 = 2 # AC Power value + AC Power scale factor
40087 = 1 # Total Real Power (sum of active phases)
40091 = 1 # AC Real Power Scale Factor

[Kostal_mit_KSEM]
# "cfgInverterType":3
# SlaveID=240
Port = 502
40087 = 1 # Total Real Power (sum of active phases)
40091 = 1 # AC Real Power Scale Factor

[Huawei]
# "cfgInverterType":4
Port = 502
37113 = 1 # Active power
37765 = 1 # [Energystorage]Charge/Discharge power (optional)

[SMA]
# "cfgInverterType":5
Port = 502
30867 = 1 # Metering.GridMs.TotWOut
30865 = 1 # Metering.GridMs.TotWIn

[Victron]
# "cfgInverterType":6
Port = 502
820 = 3 # com.victronenergy.system --> Grid L1 - Power

[E3DC]
# "cfgInverterType":7
Port = 502
40074 = 1 # Leistung am Netzübergabepunkt

[Kostal_Plenticore]
# "cfgInverterType":8
Port = 1502
172 = 1 # Total AC active power
23 changes: 14 additions & 9 deletions wbecModbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,36 @@

print("wbec Modbus-TCP-Kompatibilitätsprüfung")

config = configparser.ConfigParser()
config = configparser.ConfigParser(inline_comment_prefixes='#')
config.read('cfg.ini')

cfg = config['Section 1']
cfg = config['Configuration']
typ = config['Configuration']['Typ']

for key in config['Section 1']:
print(key.ljust(18) + ": " + config['Section 1'][key])
for key in cfg:
print(key.ljust(18) + ": " + cfg[key])
print('Port'.ljust(18) + ": " + config[typ]['Port'])
print("...bitte warten...")

try:
client = ModbusTcpClient(cfg['cfgInverterIp'], port=cfg['cfgInverterPort'])
client = ModbusTcpClient(cfg['cfgInverterIp'], port=config[typ]['Port'])
client.connect()
print("Registerwerte:")
for key in config['Register']:
response = client.read_holding_registers(int(key), int(config['Register'][key]), slave=int(cfg['cfgInverterAddr']), unit=0x01)
for key in config[typ]:
if not key.isdigit():
continue
# If key contains a register number, then read it
response = client.read_holding_registers(int(key), int(config[typ][key]), slave=int(cfg['cfgInverterAddr']), unit=0x01)

# Check if reading was successful
if response.isError():
print(f"Register {int(key) + i}: Fehler: ", response)
print(f"Register {int(key)}: Fehler: ", response)
else:
for i, register_value in enumerate(response.registers):
print(f"Register {int(key) + i}: {register_value}")

client.close()

except ConnectionException:
print("Fehler: Server " + cfg['cfgInverterIp'] + ", Port " + cfg['cfgInverterPort'] + " nicht erreichbar")
print("Fehler: Server " + cfg['cfgInverterIp'] + ", Port " + config[typ]['Port'] + " nicht erreichbar")

0 comments on commit 57f1d72

Please sign in to comment.