Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions growatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"""
import logging
import time
import struct
from pymodbus.exceptions import ModbusIOException

from protocol_settings import registry_map_entry, protocol_settings
from protocol_settings import Data_Type, registry_map_entry, protocol_settings

# Codes
StateCodes = {
Expand Down Expand Up @@ -145,10 +146,14 @@ def read_input_register(self) -> dict[str,str]:
for item in self.protocolSettings.input_registry_map:
value = ''

if item.bytes == 1: #read byte

if item.data_type == Data_Type.BYTE: #read byte
value = float(registry[item.register])
elif item.bytes == 2: #read double
elif item.data_type == Data_Type.UINT: #read uint
value = float((registry[item.register] << 16) + registry[item.register + 1])
elif item.data_type == Data_Type.INT: #read int
value = int.from_bytes(bytes([registry[item.register], registry[item.register + 1]]), byteorder='little', signed=True)


if item.unit_mod != float(1):
value = value * item.unit_mod
Expand Down
33 changes: 29 additions & 4 deletions protocol_settings.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import csv
from dataclasses import dataclass
from enum import Enum
import json
import re
import os


class Data_Type(Enum):
BYTE = 1
USHORT = 2
UINT = 3
SHORT = 4
INT = 5
@classmethod
def fromString(cls, name : str):
name = name.strip().upper()
return getattr(cls, name)


@dataclass
class registry_map_entry:
register : int
variable_name : str
documented_name : str
unit : str
unit_mod : float
bytes : int = 1
data_type : Data_Type = Data_Type.BYTE

class protocol_settings:
protocol : str
Expand Down Expand Up @@ -110,13 +123,20 @@ def load__registry(self, path) -> list[registry_map_entry]:

if numeric_part == 0:
numeric_part = float(1)

data_type = Data_Type.BYTE

#optional row, only needed for non-default data types
if 'data_type' in row and row['data_type']:
data_type = Data_Type.fromString(row['data type'])

item = registry_map_entry(
register= int(row['register']),
variable_name= variable_name,
documented_name = row['documented name'],
unit= str(character_part),
unit_mod= numeric_part
unit_mod= numeric_part,
data_type= data_type
)

registry_map.append(item)
Expand All @@ -130,7 +150,12 @@ def load__registry(self, path) -> list[registry_map_entry]:
and registry_map[index-1].documented_name.replace('_h', '_l') == item.documented_name
):
combined_item = registry_map[index-1]
combined_item.bytes = 2

if not combined_item.data_type:
if registry_map[index].data_type != Data_Type.BYTE:
combined_item.data_type = registry_map[index].data_type
else:
combined_item.data_type = Data_Type.INT

if combined_item.documented_name == combined_item.variable_name:
combined_item.variable_name = combined_item.variable_name[:-2].strip()
Expand Down Expand Up @@ -188,4 +213,4 @@ def load__holding_registry_map(self, file : str = '', settings_dir : str = ''):
self.holding_registry_size = item.register


settings = protocol_settings('v0.14')
#settings = protocol_settings('v0.14')
180 changes: 90 additions & 90 deletions protocols/v0.14.input_registry_map.csv
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
register;variable name;documented name;description;value;unit;note;;;;;;;;;;
0;;System Status;System run state;0: Standby;1; PV an Grid Combine Discharge2: Discharge;3: Fault;4: Flash;5: PV charge;6: AC charge;7: Combine charge;8: Combine charge and Bypass;9: PV charge and Bypass;10: AC charge and Bypass; 11: Bypass;12: PV charge andDischarge
1;PV1 Voltage;Vpv1;PV1 voltage;;0.1V;;;;;;;;;;;
2;PV2 Voltage;Vpv2;PV2 voltage;;0.1V;;;;;;;;;;;
3;PV1 Watts;Ppv1 H;PV1 charge power (high);;0.1W;;;;;;;;;;;
4;;Ppv1 L;PV1 charge power (low);;0.1W;;;;;;;;;;;
5;PV2 Watts;Ppv2 H;PV2 charge power (high);;0.1W;;;;;;;;;;;
6;;Ppv2 L;PV2 charge power (low);;0.1W;;;;;;;;;;;
7;Buck1 Current;Buck1Curr;Buck1 current;;0.1A;;;;;;;;;;;
8;Buck2 Current;Buck2Curr;Buck2 current;;0.1A;;;;;;;;;;;
9;Output Wattage;OP_Watt H;Output active power (high);;0.1W;;;;;;;;;;;
10;;OP_Watt L;Output active power (low);;0.1W;;;;;;;;;;;
11;Output VA;OP_VA H;Output apparent power (high);;0.1VA;;;;;;;;;;;
12;;OP_VA L;Output apparent power (low);;0.1VA;;;;;;;;;;;
13;AC Charge Watts;ACChr_Watt H;AC charge watt (high);;0.1W;;;;;;;;;;;
14;;ACChr_Watt L;AC charge watt (low);;0.1W;;;;;;;;;;;
15;AC Charge VA;ACChr_VA H;AC charge apparent power (high);;0.1VA;;;;;;;;;;;
16;;ACChr_VA L;AC charge apparent power (low);;0.1VA;;;;;;;;;;;
17;Battery Voltage;Bat Volt;Battery volt (M3);;0.01V;;;;;;;;;;;
18;Battery SOC;BatterySOC;Battery SOC;0~100;1.00%;;;;;;;;;;;
19;Bus Voltage;Bus Volt;Bus Voltage;;0.1V;;;;;;;;;;;
20;Grid Voltage;Grid Volt;AC input Volt;;0.1V;;;;;;;;;;;
21;Grid Hz;Line Freq;AC input frequency;;0;;;;;;;;;;;
22;Output Voltage;OutputVolt;AC output Volt;;0.1V;;;;;;;;;;;
23;Output Hz;OutputFreq;AC output frequency;;0.01Hz;;;;;;;;;;;
24;Output DCV;Ouput DCV;Ouput DC Volt;;0.1V;;;;;;;;;;;
25;;InvTemp;Inv Temperature;;0.1C;;;;;;;;;;;
26;;DcDc Temp;DC-DC Temperature;;0.1C;;;;;;;;;;;
27;Load Percentage;LoadPercent;Load Percent;0~1000;0.10%;;;;;;;;;;;
28;Battery Port Voltage;Bat_s_Volt;Battery-port volt (DSP);;0.01V;;;;;;;;;;;
29;Battery Bus Voltage;Bat_Volt_DSP;Battery-bus volt (DSP);;0.01V;;;;;;;;;;;
30;;Time total H;Work time total (high);;0.5;;;;;;;;;;;
31;;Time total L;Work time total (low);;0. 5S;;;;;;;;;;;
32;Buck1 Temperature;Buck1_NTC;Buck1 Temperature;;0.1C;;;;;;;;;;;
33;Buck2 Temperature;Buck2_NTC;Buck2 Temperature;;0.1C;;;;;;;;;;;
34;Output Current;OP_Curr;Output Current;;0.1A;;;;;;;;;;;
35;Inverter Current;Inv_Curr;Inv Current;;0.1A;;;;;;;;;;;
36;AC Input Watts;AC_InWatt H;AC input watt (high);;0.1W;;;;;;;;;;;
37;;AC_InWatt L;AC input watt (low);;0.1W;;;;;;;;;;;
38;AC Input VA;AC_InVA H;AC input apparent power (high);;0.1VA;;;;;;;;;;;
39;;AC_InVA L;AC input apparent power (low);;0.1VA;;;;;;;;;;;
40;;Fault bit;fault bit;&*1;;;;;;;;;;;;
41;;Warning bit;Warning bit;&*1;;;;;;;;;;;;
42;;Warning bit high;;;;;;;;;;;;;;
43;;warning value;warning value;;;;;;;;;;;;;
44;;DTC;Device Type Code;&*6;;;;;;;;;;;;
45;;Check Step;Product check step;1:PV1 charge power check 2:PV2 charge power check 3:AC charge Powercheck;;;;;;;;;;;;
46;;Production Line Mode;Production Line Mode;0: Not at Production Line Mode 1: Production Line Mode 2: Production LineClear Fault Mode;;;;;;;;;;;;
47;;ConstantPowerOKFlag;Constant Power OK Flag;0: Not OK 1: OK;;;;;;;;;;;;
48;PV1 KWH Today;Epv1_today H;PV Energy today;;;;;;;;;;;;;
49;;Epv1_today L;PV Energy today;;0.1kWh;;;;;;;;;;;
50;PV1 KWH Total;Epv1_total H;PV Energy total;;;;;;;;;;;;;
51;;Epv1_total L;PV Energy total;;0.1kWh;;;;;;;;;;;
52;PV2 KWH Today;Epv2_today H;PV Energy today;;;;;;;;;;;;;
53;;Epv2_today L;PV Energy today;;0.1kWh;;;;;;;;;;;
54;PV2 KWH Total;Epv2_total H;PV Energy total;;;;;;;;;;;;;
55;;Epv2_total L;PV Energy total;;0.1kWh;;;;;;;;;;;
56;AC Input KWH Today;Eac_chrToday H;AC charge Energy today;;;;;;;;;;;;;
57;;Eac_chrToday L;AC charge Energy today;;0.1kWh;;;;;;;;;;;
58;AC Input KWH Total;Eac_chrTotal H;AC charge Energy total;;;;;;;;;;;;;
59;;Eac_chrTotal L;AC charge Energy total;;0.1kWh;;;;;;;;;;;
60;Battery Discharge KWH Today;Ebat_dischrToday H;Bat discharge Energy today;;;;;;;;;;;;;
61;;Ebat_dischrToday L;Bat discharge Energy today;;0.1kWh;;;;;;;;;;;
62;Battery Discharge KWH Total;Ebat_dischrTotal H;Bat discharge Energy total;;;;;;;;;;;;;
63;;Ebat_dischrTotal L;Bat discharge Energy total;;0.1kWh;;;;;;;;;;;
64;AC Discharge KWH Today;Eac_dischrToday H;AC discharge Energy today;;;;;;;;;;;;;
65;;Eac_dischrToday L;AC discharge Energy today;;0.1kWh;;;;;;;;;;;
66;AC Discharge KWH Total;Eac_dischrTotal H;AC discharge Energy total;;;;;;;;;;;;;
67;;Eac_dischrTotal L;AC discharge Energy total;;0.1kWh;;;;;;;;;;;
68;AC Charge Current;ACChrCurr;AC Charge Battery Current;;0.1;;;;;;;;;;;
69;AC Discharge Watts;AC_DisChrWatt H;AC discharge watt (high);;0.1W;;;;;;;;;;;
70;;AC_DisChrWatt L;AC discharge watt (low);;0.1W;;;;;;;;;;;
71;AC Discharge VA;AC_DisChrVA H;AC discharge apparent power (high);;0.1VA;;;;;;;;;;;
72;;AC_DisChrVA L;AC discharge apparent power (low);;0.1VA;;;;;;;;;;;
73;Battery Discharge Watts;Bat_DisChrWatt H;Bat discharge watt (high);;0.1W;;;;;;;;;;;
74;;Bat_DisChrWatt L;Bat discharge watt (low);;0.1W;;;;;;;;;;;
75;Battery Discharge VA;Bat_DisChrVA H;Bat discharge apparent power (high);;0.1VA;;;;;;;;;;;
76;;Bat_DisChrVA L;Bat discharge apparent power (low);;0.1VA;;;;;;;;;;;
77;Battery Input Watts;Bat_Watt H;Bat watt (high);(signed int 32) Positive:Battery Discharge Power Negative: Battery Charge Power;0.1W;;0.1W;;;;;;;;;
78;;Bat_Watt L;Bat watt (low);;0.1W;;;;;;;;;;;
79;;uwSlaveExistCnt ;uwSlaveExistCnt ;;;;;;;;;;;;;
80;Battery Over Charge Flag;BatOverCharge ;Battery Over Charge Flag ;0:Battery not over charge 1:Battery over charge ;; ;;;;;;;;;;
81;MPPT Fan Speed Percent;MpptFanSpeed ;Fan speed of MPPT Charger ;0~100 ;1.00%;;;;;;;;;;;
82;Inverter Fan Speed Percent;InvFanSpeed ;Fan speed of Inverter ;0~100 ;1.00%;;;;;;;;;;;
83;Total Charge Current;TotalChgCur ;Total Charge current ;;0.1A;;;;;;;;;;;
85;;Eop_dischrToday H ;Op discharge Enerday today ;;;;;;;;;;;;;
86;;Eop_dischrToday L ;;;;;;;;;;;;;;
87;;Eop_dischrTotal H ;Op discharge Enerday total ;;;;;;;;;;;;;
88;;Eop_dischrTotal L ;;;;;;;;;;;;;;
90;Parallel Charge Current;ParaChgCurr ;Para system charge current ;;0.1A;;;;;;;;;;;
register;variable name;documented name;description;value;data type;unit;note;;;;;;;;;;
0;;System Status;System run state;0: Standby;;1; PV an Grid Combine Discharge2: Discharge;3: Fault;4: Flash;5: PV charge;6: AC charge;7: Combine charge;8: Combine charge and Bypass;9: PV charge and Bypass;10: AC charge and Bypass; 11: Bypass;12: PV charge andDischarge
1;PV1 Voltage;Vpv1;PV1 voltage;;;0.1V;;;;;;;;;;;
2;PV2 Voltage;Vpv2;PV2 voltage;;;0.1V;;;;;;;;;;;
3;PV1 Watts;Ppv1 H;PV1 charge power (high);;;0.1W;;;;;;;;;;;
4;;Ppv1 L;PV1 charge power (low);;;0.1W;;;;;;;;;;;
5;PV2 Watts;Ppv2 H;PV2 charge power (high);;;0.1W;;;;;;;;;;;
6;;Ppv2 L;PV2 charge power (low);;;0.1W;;;;;;;;;;;
7;Buck1 Current;Buck1Curr;Buck1 current;;;0.1A;;;;;;;;;;;
8;Buck2 Current;Buck2Curr;Buck2 current;;;0.1A;;;;;;;;;;;
9;Output Wattage;OP_Watt H;Output active power (high);;;0.1W;;;;;;;;;;;
10;;OP_Watt L;Output active power (low);;;0.1W;;;;;;;;;;;
11;Output VA;OP_VA H;Output apparent power (high);;;0.1VA;;;;;;;;;;;
12;;OP_VA L;Output apparent power (low);;;0.1VA;;;;;;;;;;;
13;AC Charge Watts;ACChr_Watt H;AC charge watt (high);;;0.1W;;;;;;;;;;;
14;;ACChr_Watt L;AC charge watt (low);;;0.1W;;;;;;;;;;;
15;AC Charge VA;ACChr_VA H;AC charge apparent power (high);;;0.1VA;;;;;;;;;;;
16;;ACChr_VA L;AC charge apparent power (low);;;0.1VA;;;;;;;;;;;
17;Battery Voltage;Bat Volt;Battery volt (M3);;;0.01V;;;;;;;;;;;
18;Battery SOC;BatterySOC;Battery SOC;0~100;;1.00%;;;;;;;;;;;
19;Bus Voltage;Bus Volt;Bus Voltage;;;0.1V;;;;;;;;;;;
20;Grid Voltage;Grid Volt;AC input Volt;;;0.1V;;;;;;;;;;;
21;Grid Hz;Line Freq;AC input frequency;;;0;;;;;;;;;;;
22;Output Voltage;OutputVolt;AC output Volt;;;0.1V;;;;;;;;;;;
23;Output Hz;OutputFreq;AC output frequency;;;0.01Hz;;;;;;;;;;;
24;Output DCV;Ouput DCV;Ouput DC Volt;;;0.1V;;;;;;;;;;;
25;;InvTemp;Inv Temperature;;;0.1C;;;;;;;;;;;
26;;DcDc Temp;DC-DC Temperature;;;0.1C;;;;;;;;;;;
27;Load Percentage;LoadPercent;Load Percent;0~1000;;0.10%;;;;;;;;;;;
28;Battery Port Voltage;Bat_s_Volt;Battery-port volt (DSP);;;0.01V;;;;;;;;;;;
29;Battery Bus Voltage;Bat_Volt_DSP;Battery-bus volt (DSP);;;0.01V;;;;;;;;;;;
30;;Time total H;Work time total (high);;;0.5;;;;;;;;;;;
31;;Time total L;Work time total (low);;;0. 5S;;;;;;;;;;;
32;Buck1 Temperature;Buck1_NTC;Buck1 Temperature;;;0.1C;;;;;;;;;;;
33;Buck2 Temperature;Buck2_NTC;Buck2 Temperature;;;0.1C;;;;;;;;;;;
34;Output Current;OP_Curr;Output Current;;;0.1A;;;;;;;;;;;
35;Inverter Current;Inv_Curr;Inv Current;;;0.1A;;;;;;;;;;;
36;AC Input Watts;AC_InWatt H;AC input watt (high);;;0.1W;;;;;;;;;;;
37;;AC_InWatt L;AC input watt (low);;;0.1W;;;;;;;;;;;
38;AC Input VA;AC_InVA H;AC input apparent power (high);;;0.1VA;;;;;;;;;;;
39;;AC_InVA L;AC input apparent power (low);;;0.1VA;;;;;;;;;;;
40;;Fault bit;fault bit;&*1;;;;;;;;;;;;;
41;;Warning bit;Warning bit;&*1;;;;;;;;;;;;;
42;;Warning bit high;;;;;;;;;;;;;;;
43;;warning value;warning value;;;;;;;;;;;;;;
44;;DTC;Device Type Code;&*6;;;;;;;;;;;;;
45;;Check Step;Product check step;1:PV1 charge power check 2:PV2 charge power check 3:AC charge Powercheck;;;;;;;;;;;;;
46;;Production Line Mode;Production Line Mode;0: Not at Production Line Mode 1: Production Line Mode 2: Production LineClear Fault Mode;;;;;;;;;;;;;
47;;ConstantPowerOKFlag;Constant Power OK Flag;0: Not OK 1: OK;;;;;;;;;;;;;
48;PV1 KWH Today;Epv1_today H;PV Energy today;;;;;;;;;;;;;;
49;;Epv1_today L;PV Energy today;;;0.1kWh;;;;;;;;;;;
50;PV1 KWH Total;Epv1_total H;PV Energy total;;;;;;;;;;;;;;
51;;Epv1_total L;PV Energy total;;;0.1kWh;;;;;;;;;;;
52;PV2 KWH Today;Epv2_today H;PV Energy today;;;;;;;;;;;;;;
53;;Epv2_today L;PV Energy today;;;0.1kWh;;;;;;;;;;;
54;PV2 KWH Total;Epv2_total H;PV Energy total;;;;;;;;;;;;;;
55;;Epv2_total L;PV Energy total;;;0.1kWh;;;;;;;;;;;
56;AC Input KWH Today;Eac_chrToday H;AC charge Energy today;;;;;;;;;;;;;;
57;;Eac_chrToday L;AC charge Energy today;;;0.1kWh;;;;;;;;;;;
58;AC Input KWH Total;Eac_chrTotal H;AC charge Energy total;;;;;;;;;;;;;;
59;;Eac_chrTotal L;AC charge Energy total;;;0.1kWh;;;;;;;;;;;
60;Battery Discharge KWH Today;Ebat_dischrToday H;Bat discharge Energy today;;;;;;;;;;;;;;
61;;Ebat_dischrToday L;Bat discharge Energy today;;;0.1kWh;;;;;;;;;;;
62;Battery Discharge KWH Total;Ebat_dischrTotal H;Bat discharge Energy total;;;;;;;;;;;;;;
63;;Ebat_dischrTotal L;Bat discharge Energy total;;;0.1kWh;;;;;;;;;;;
64;AC Discharge KWH Today;Eac_dischrToday H;AC discharge Energy today;;;;;;;;;;;;;;
65;;Eac_dischrToday L;AC discharge Energy today;;;0.1kWh;;;;;;;;;;;
66;AC Discharge KWH Total;Eac_dischrTotal H;AC discharge Energy total;;;;;;;;;;;;;;
67;;Eac_dischrTotal L;AC discharge Energy total;;;0.1kWh;;;;;;;;;;;
68;AC Charge Current;ACChrCurr;AC Charge Battery Current;;;0.1;;;;;;;;;;;
69;AC Discharge Watts;AC_DisChrWatt H;AC discharge watt (high);;;0.1W;;;;;;;;;;;
70;;AC_DisChrWatt L;AC discharge watt (low);;;0.1W;;;;;;;;;;;
71;AC Discharge VA;AC_DisChrVA H;AC discharge apparent power (high);;;0.1VA;;;;;;;;;;;
72;;AC_DisChrVA L;AC discharge apparent power (low);;;0.1VA;;;;;;;;;;;
73;Battery Discharge Watts;Bat_DisChrWatt H;Bat discharge watt (high);;;0.1W;;;;;;;;;;;
74;;Bat_DisChrWatt L;Bat discharge watt (low);;;0.1W;;;;;;;;;;;
75;Battery Discharge VA;Bat_DisChrVA H;Bat discharge apparent power (high);;;0.1VA;;;;;;;;;;;
76;;Bat_DisChrVA L;Bat discharge apparent power (low);;;0.1VA;;;;;;;;;;;
77;Battery Input Watts;Bat_Watt H;Bat watt (high);(signed int 32) Positive:Battery Discharge Power Negative: Battery Charge Power;INT;0.1W;;0.1W;;;;;;;;;
78;;Bat_Watt L;Bat watt (low);;;0.1W;;;;;;;;;;;
79;;uwSlaveExistCnt ;uwSlaveExistCnt ;;;;;;;;;;;;;;
80;Battery Over Charge Flag;BatOverCharge ;Battery Over Charge Flag ;0:Battery not over charge 1:Battery over charge ;;; ;;;;;;;;;;
81;MPPT Fan Speed Percent;MpptFanSpeed ;Fan speed of MPPT Charger ;0~100 ;;1.00%;;;;;;;;;;;
82;Inverter Fan Speed Percent;InvFanSpeed ;Fan speed of Inverter ;0~100 ;;1.00%;;;;;;;;;;;
83;Total Charge Current;TotalChgCur ;Total Charge current ;;;0.1A;;;;;;;;;;;
85;;Eop_dischrToday H ;Op discharge Enerday today ;;;;;;;;;;;;;;
86;;Eop_dischrToday L ;;;;;;;;;;;;;;;
87;;Eop_dischrTotal H ;Op discharge Enerday total ;;;;;;;;;;;;;;
88;;Eop_dischrTotal L ;;;;;;;;;;;;;;;
90;Parallel Charge Current;ParaChgCurr ;Para system charge current ;;;0.1A;;;;;;;;;;;