-
Notifications
You must be signed in to change notification settings - Fork 4
/
read_invertor_errors.py
158 lines (143 loc) · 6.7 KB
/
read_invertor_errors.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
import argparse
from pymodbus.client.sync import ModbusTcpClient
from pymodbus.constants import Endian
from pymodbus.exceptions import ConnectionException
from pymodbus.payload import BinaryPayloadDecoder
parser = argparse.ArgumentParser()
parser.add_argument('--host', help="SAJ Inverter IP",
type=str, required=True)
parser.add_argument('--port', help="SAJ Inverter Port",
type=int, required=True)
args = parser.parse_args()
address = 0x0101 # First register with Inverter errors.
count = 6 # Read this amount of registers
connected = False
client = ModbusTcpClient(host=args.host, port=args.port, timeout=3)
client.connect()
FAULT_MESSAGES = {
0: {
0x80000000: "Code 81: Lost Communication D<->C",
0x00080000: "Code 48: Master Fan4 Error",
0x00040000: "Code 47: Master Fan3 Error",
0x00020000: "Code 46: Master Fan2 Error",
0x00010000: "Code 45: Master Fan1 Error",
0x00002000: "Code 43: Master HW Phase3 Current High",
0x00001000: "Code 42: Master HW Phase2 Current High",
0x00000800: "Code 41: Master HW Phase1 Current High",
0x00000400: "Code 40: Master HWPV2 Current High",
0x00000200: "Code 39: Master HWPV1 Current High",
0x00000100: "Code 38: Master HWBus Voltage High",
0x00000010: "Code 37: Master Phase3 Current High",
0x00000008: "Code 36: Master Phase2 Current High",
0x00000004: "Code 35: Master Phase1 Current High",
0x00000002: "Code 34: Master Bus Voltage Low",
0x00000001: "Code 33: Master Bus Voltage High",
},
1: {
0x80000000: "Code 32: Master Bus Voltage Balance Error",
0x40000000: "Code 31: Master ISO Error",
0x20000000: "Code 30: Master Phase3 DCI Error",
0x10000000: "Code 29: Master Phase2 DCI Error",
0x08000000: "Code 28: Master Phase1 DCI Error",
0x04000000: "Code 27: Master GFCI Error",
0x02000000: "Code 26: Master Phase3 No Grid Error",
0x01000000: "Code 25: Master Phase2 No Grid Error",
0x00800000: "Code 24: Master Phase1 No Grid Error",
0x00400000: "Code 23: Master Phase3 Frequency Low",
0x00200000: "Code 22: Master Phase3 Frequency High",
0x00100000: "Code 21: Master Phase2 Frequency Low",
0x00080000: "Code 20: Master Phase2 Frequency High",
0x00040000: "Code 19: Master Phase1 Frequency Low",
0x00020000: "Code 18: Master Phase1 Frequency High",
0x00010000: "Code 17: Master Phase3 Voltage 10Min High",
0x00008000: "Code 16: Master Phase2 Voltage 10Min High",
0x00004000: "Code 15: Master Phase1 Voltage 10Min High",
0x00002000: "Code 14: Master Phase3 Voltage Low",
0x00001000: "Code 13: Master Phase3 Voltage High",
0x00000800: "Code 12: Master Phase2 Voltage Low",
0x00000400: "Code 11: Master Phase2 Voltage High",
0x00000200: "Code 10: Master Phase1 Voltage Low",
0x00000100: "Code 09: Master Phase1 Voltage High",
0x00000080: "Code 08: Master Current Sensor Error",
0x00000040: "Code 07: Master DCI Device Error",
0x00000020: "Code 06: Master GFCI Device Error",
0x00000010: "Code 05: Master Lost Communication M<->S",
0x00000008: "Code 04: Master Temperature Low Error",
0x00000004: "Code 03: Master Temperature High Error",
0x00000002: "Code 02: Master EEPROM Error",
0x00000001: "Code 01: Master Relay Error",
},
2: {
0x40000000: "Code 80: Slave PV Voltage High Error",
0x20000000: "Code 79: Slave PV2 Current High Error",
0x10000000: "Code 78: Slave PV1 Current High Error",
0x08000000: "Code 77: Slave PV2 Voltage High Error",
0x04000000: "Code 76: Slave PV1 Voltage High Error",
0x02000000: "Code 75: Slave Phase3 No Grid Error",
0x01000000: "Code 74: Slave Phase2 No Grid Error",
0x00800000: "Code 73: Slave Phase1 No Grid Error",
0x00400000: "Code 72: Slave Phase3 Frequency Low",
0x00200000: "Code 71: Slave Phase3 Frequency High",
0x00100000: "Code 70: Slave Phase2 Frequency Low",
0x00080000: "Code 69: Slave Phase2 Frequency High",
0x00040000: "Code 68: Slave Phase1 Frequency Low",
0x00020000: "Code 67: Slave Phase1 Frequency High",
0x00010000: "Code 66: Slave Phase3 Voltage Low",
0x00008000: "Code 65: Slave Phase3 Voltage High",
0x00004000: "Code 64: Slave Phase2 Voltage Low",
0x00002000: "Code 63: Slave Phase2 Voltage High",
0x00001000: "Code 62: Slave Phase1 Voltage Low",
0x00000800: "Code 61: Slave Phase1 Voltage High",
0x00000400: "Code 60: Slave Phase3 DCI Consis Error",
0x00000200: "Code 59: Slave Phase2 DCI Consis Error",
0x00000100: "Code 58: Slave Phase1 DCI Consis Error",
0x00000080: "Code 57: Slave GFCI Consis Error",
0x00000040: "Code 56: Slave Phase3 Frequency Consis Error",
0x00000020: "Code 55: Slave Phase2 Frequency Consis Error",
0x00000010: "Code 54: Slave Phase1 Frequency Consis Error",
0x00000008: "Code 53: Slave Phase3 Voltage Consis Error",
0x00000004: "Code 52: Slave Phase2 Voltage Consis Error",
0x00000002: "Code 51: Slave Phase1 Voltage Consis Error",
0x00000001: "Code 50: Slave Lost Communication between M<->S",
},
}
try:
inverter_data = client.read_holding_registers(
unit=1, address=address, count=count)
connected = True
except ConnectionException as ex:
print(f'Connecting to device {args.host} failed!')
connected = False
if connected:
if not inverter_data.isError():
decoder = BinaryPayloadDecoder.fromRegisters(
inverter_data.registers, byteorder=Endian.Big)
faultMsg0 = decoder.decode_32bit_uint()
faultMsg1 = decoder.decode_32bit_uint()
faultMsg2 = decoder.decode_32bit_uint()
print("faultMsg "
+ "{0:#010x}".format(faultMsg0)
+ " "
+ "{0:#010x}".format(faultMsg1)
+ " "
+ "{0:#010x}".format(faultMsg2)
)
faultMsg = []
if faultMsg0:
for code, mesg in FAULT_MESSAGES[0].items():
if faultMsg0 & code:
faultMsg.append(mesg)
if faultMsg1:
for code, mesg in FAULT_MESSAGES[1].items():
if faultMsg1 & code:
faultMsg.append(mesg)
if faultMsg2:
for code, mesg in FAULT_MESSAGES[2].items():
if faultMsg2 & code:
faultMsg.append(mesg)
error = ", ".join(faultMsg)
if error:
print("Fault message: " + error)
else:
print("No faults")
client.close()