-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWallbox_read_Actual.py
230 lines (207 loc) · 8.41 KB
/
Wallbox_read_Actual.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#######################################################
# Modbus reading Python script. #
# More details in document #
# Modbus Map Versicharge Gen 3 #
#######################################################
#
# 2022 achgut
#
#************************************************************************************
#
# Verwendete Versicharge GEN 3:
#// Versicharge GEN3 FW2.118 oder höher
#// Commercial Version (Reg 22 = 2), One Outlet: (Reg 24 = 1)
#// Integrated MID (Reg 30 = 4)
#// Order Number: 8EM1310-3EJ04-0GA0
#
#//https://support.industry.siemens.com/cs/attachments/109814359/versicharge_wallbox_modBus_map_en-US-FINAL.pdf
#
#// Gefundene Fehler:
# // Status Wallbox (A-F): Register 1601 nicht im ModbusMap dokumentiert.
# // Active Power Phase Sum wird bei Strömen über 10A falsch berechnet (Register 1665)
# // Minimal Current: Muss als 7A eingestellt werden. Regelung dann auf 6A.
# // Phasenumschaltung funktioniert nicht - Läd immmer mit 3 Phasen teilweise Absturz Wallbox
# Update FW 1.120:
# Fallback Settings (Reg 1660/1661) funktionieren (lesbar)
#************************************************************************************
#Imports
from pymodbus.client import ModbusTcpClient
import time
from datetime import datetime
from struct import *
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
#Initialisations
UNIT = 1
separator=80 #Separator line length
clientPort=502 #Port for modbus connection for reading charger's data
#PLEASE CHANGE CHARGER'S IP ADDRESS FIRST
################################################
clientIP="192.168.178.63" #Charger's IP address
################################################
def main():
try:
time.sleep(2)
#Try to connect to client
client = ModbusTcpClient(clientIP, clientPort) #Use port 502 for reading charger's data
connection = client.connect()
#Print connection info
print("*" * separator)
print("Reading data from Versicharge Wallbox: " + str(clientIP) + ":" + str(clientPort))
print("-" * separator)
print(">>> REAL-TIME VALUES Dynamic <<<")
print("-" * separator)
print(datetime.now())
print("-" * separator)
# FW
response = client.read_holding_registers(address=31,count=10,unit=UNIT)
output = response.registers
liste = list()
for i in output:
lower = i & 0b11111111
upper = (i & 0b1111111100000000) >> 8
liste.append(chr(upper))
liste.append(chr(lower))
strStatus = "FW: " + "".join(liste)
print(strStatus)
#Temperature PCB
response = client.read_holding_registers(address=1602,count=1,unit=UNIT)
t = response.registers[0]
if t > 65000 :
t = t - 65536
strStatus = "Temperatur PCB: " + str(t) + "°C"
print(strStatus)
#Reg 1599 - EVSE State
response = client.read_holding_registers(address=1599,count=1,unit=UNIT)
print("EVSE State: " + str(response.registers[0]))
#Reg 1600 - EVSE Error Code
response = client.read_holding_registers(address=1600,count=1,unit=UNIT)
print("EVSE Error Code: " + str(response.registers[0]))
#Charger Status
response = client.read_holding_registers(address=1601,count=1,unit=UNIT)
strStatus = "Charger Status (OCPP State): " + str(response.registers[0])
chargerstatus = response.registers[0]
print(strStatus)
if(response.registers == [1]):
strStatus = "Charger Status: A (Power On)"
print(strStatus)
elif(response.registers == [2]):
strStatus = "Charger Status: B (Connected)"
print(strStatus)
elif(response.registers == [3]):
strStatus = "Charger Status: C (Charging)"
print(strStatus)
elif(response.registers == [4]):
strStatus = "Charger Status: C (Charging)"
print(strStatus)
elif(response.registers == [5]):
responseMaxCurrent = client.read_holding_registers(address=1633,count=1,unit=UNIT)
if(responseMaxCurrent.registers == 0):
strStatus = "Charger Status D und Pause an"
print(strStatus)
else:
strStatus = "Charger Status D und keine Pause"
print(strStatus)
else:
print("Charging Fehler F")
#Charger Delay
response = client.read_holding_registers(address=26,count=1,unit=UNIT)
print("Charger Delay: " + str(response.registers[0]))
#RFID on?
response = client.read_holding_registers(address=79,count=1,unit=UNIT)
strStatus = "RFID Status: " + str(response.registers[0])
print(strStatus)
if(response.registers == [0]):
strStatus = "RFID disabled"
print(strStatus)
elif(response.registers == [1]):
strStatus = "RFID enabled"
print(strStatus)
else:
print("RFID nicht erkannt")
# RFID Karte erkannt
helper = 0
response = client.read_holding_registers(address=338,count=5) #,unit=UNIT)
try:
strStatus = "RFID Karte: "
while helper < 5 :
strStatus = strStatus + str(hex(response.registers[helper])) + " "
helper += 1
print(strStatus)
except:
print("Register " + str(338) + " :Error " + str(response))
#MaxCurrent
response = client.read_holding_registers(address=1633,count=1,unit=UNIT)
print("Max Charging Current: " + str(response.registers[0]) + " A")
#Pausiert?
response = client.read_holding_registers(address=1633,count=1,unit=UNIT)
if(response.registers == [0]):
strStatus = "Pause an : " + str(response.registers[0])
print(strStatus)
else:
strStatus = "Pause aus : " + str(response.registers[0])
print(strStatus)
#1 oder 3 Phasig
response = client.read_holding_registers(address=1642,count=1,unit=UNIT)
if(response.registers == [1]):
strStatus = "Phases for Charging: 3 Phasen"
print(strStatus)
elif(response.registers == [0]):
strStatus = "Phases for Charging: 1 Phase"
print(strStatus)
else:
print("Phase nicht erkannt")
#Current L1 - L3
response = client.read_holding_registers(address=1647,count=4,unit=UNIT)
strStatus = "Charging Current (L1 L2 L3 Sum): " + str(response.registers) + " A"
print(strStatus)
#Voltage L1 - L3
response = client.read_holding_registers(address=1651,count=3,unit=UNIT)
strStatus = "Charging Voltage (L1 L2 L3): " + str(response.registers) + " V zu N"
print(strStatus)
#Power L1 - L3
response = client.read_holding_registers(address=1662,count=4,unit=UNIT)
strStatus = "Charging Power (L1 L2 L3 Sum): " + str(response.registers) + " W"
print(strStatus)
#Apparent Power L1 - L3
response = client.read_holding_registers(address=1670,count=4,unit=UNIT)
strStatus = "Apparent Power (L1 L2 L3 Sum): " + str(response.registers) + " VA"
print(strStatus)
#Reactive Power L1 - L3
response = client.read_holding_registers(address=1674,count=4,unit=UNIT)
helper = 0
strStatus = "Reactive Power (L1 L2 L3 Sum): "
while helper < 4 :
RP = int(response.registers[helper])
if (RP & (1 << (16 - 1))) != 0:
RP = RP - (1 << 16)
helper += 1
strStatus = strStatus + str(RP) + " "
strStatus = strStatus + "VA Reactive Power"
print(strStatus)
#Power Factor L1 - L3
response = client.read_holding_registers(address=1666,count=4,unit=UNIT)
strStatus = "Power Factor (L1 L2 L3 Sum): " + str(response.registers[0] / 1000) + " " + str(response.registers[1] / 1000) + " " + str(response.registers[2] / 1000) + " " + str(response.registers[3] / 1000) + " "
print(strStatus)
#Failsafe Settings Current
response = client.read_holding_registers(address=1660,count=1,unit=UNIT) # Register 1660 !!!!
strStatus = "Fallback Current: " + str(response.registers[0]) + "A"
print(strStatus)
#Failsafe Settings Time
response = client.read_holding_registers(address=1661,count=2,unit=UNIT) # Register 1661 !!!!
strStatus = "Fallback Time: " + str(response.registers[0]) + "s"
print(strStatus)
#Total Charing engery
response = client.read_holding_registers(address=1692,count=2,unit=UNIT)
output = response.registers
zahl = output[0] << 16
zahl |= output[1]
zahl /= 10000.0
strStatus = "Total Charging Energy (kWh): " + str(zahl) + "kWh"
print(strStatus)
client.close()
except:
print("-" * separator)
print("An error has occurred during cluster data reading!")
if __name__ == "__main__":
main()