-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWallbox_MaxCurrent_loop.py
57 lines (45 loc) · 1.58 KB
/
Wallbox_MaxCurrent_loop.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
#######################################################
# Modbus reading Python script. #
# More details in document #
# Modbus Map Versicharge Gen 3 #
#######################################################
#
# 2023 achgut
# Set MaxCurrent 10A in a loop
#Imports
from pymodbus.client import ModbusTcpClient
import time
import sys
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(amp):
try:
#Try to connect to client
client = ModbusTcpClient(clientIP, clientPort) #Use port 502 for reading charger's data
print("*" * separator)
print("Reading data from Versicharge Wallbox: " + str(clientIP) + ":" + str(clientPort))
print("-" * separator)
print(">>> REAL-TIME VALUES Dynamic <<<")
print("-" * separator)
print("-" * separator)
print(datetime.now())
print("Set to ", str(amp), " A")
while True:
time.sleep(5)
#Print Time info
client.write_register(address=1633,value=int(amp),unit=UNIT)
except:
print("-" * separator)
print("An error has occurred during cluster data reading!")
if __name__ == "__main__":
main(sys.argv[1])