-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWallbox_MaxCurrent.py
57 lines (48 loc) · 1.95 KB
/
Wallbox_MaxCurrent.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 writing Python script. #
# Set Max Charging Current #
# 1 Int als Argument mitgeben #
# #
# Modbus Map Versicharge Gen 3 #
# #
# Version 1.0 #
# November, 2022 #
# Author: Achim achgut #
#######################################################
#Imports
from pymodbus.client import ModbusTcpClient
import datetime
import sys
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
################################################
# Read data
# Charger data
def main(amp):
try:
#Try to connect to client
client = ModbusTcpClient(clientIP, clientPort) #Use port 502 for reading charger's data
connection = client.connect()
#MaxCurrent?
response = client.read_holding_registers(address=1633,count=1,unit=UNIT)
strStatus = "Max Current: " + str(response.registers[0]) + "A"
print(strStatus)
print("Set to ", str(amp), " A")
client.write_register(address=1633,value=int(amp),unit=UNIT)
response = client.read_holding_registers(address=1633,count=1,unit=UNIT)
strStatus = "Max Current: " + str(response.registers[0]) + "A"
print(strStatus)
client.close()
except:
print("-" * separator)
print("An error has occurred during cluster data reading!")
if __name__ == "__main__":
main(sys.argv[1])