-
Notifications
You must be signed in to change notification settings - Fork 8
/
umodbus_test.py
81 lines (74 loc) · 1.81 KB
/
umodbus_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# %%
# This script will test umodbus comms to a Solis Hybrid Inverter with a DLS-L LAN Data Logger
#
# It requires the umodbus module
#
# It will report the inverter temperaturem, the grid voltage and the battery state of charge
import socket
from umodbus import conf
from umodbus.client import tcp
# configuration
CFG = {
"Waveshare": {
"IP": "192.168.4.40",
"PORT": 502,
},
"S2-WL": {
"IP": "192.168.4.237",
"PORT": 502,
},
"DLS-L": {
"IP": "192.168.4.79",
"PORT": 8899,
},
} # Update with your inverter IP
devices = [
# 'S2-WL',
"Waveshare",
]
payloads = [
{
"desc": "Inverter Temperature",
"addrs": 33093,
"len": 1,
"scale": 0.1,
"uom": "C",
},
{
"desc": "Grid Voltage",
"addrs": 33251,
"len": 1,
"scale": 0.1,
"uom": "V",
},
{
"desc": "Battery SOC",
"addrs": 33139,
"len": 1,
"scale": 1,
"uom": "%",
},
{
"desc": "Battery Storage Mode (R)",
"addrs": 33132,
"len": 1,
"scale": 1,
"uom": "",
},
]
# Enable values to be signed (default is False).
conf.SIGNED_VALUES = True
sock = {}
for device in devices:
sock[device] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock[device].connect((CFG[device]["IP"], CFG[device]["PORT"]))
print(f"Device: {device}")
print("-" * 32 + "\n")
for payload in payloads:
message = tcp.read_input_registers(slave_id=1, starting_address=payload["addrs"], quantity=payload["len"])
response = tcp.send_message(message, sock[device])
val = float(response[0]) * payload["scale"]
print(f"{(payload['desc']+':'):25s}{val:5.1f} {payload['uom']}")
print("\n\n")
sock[device].close()
# %%