Skip to content

Commit 89db65a

Browse files
committed
openWB SE (openWB#3148)
* openWB SE Modbus IDs * fix scripts * fix * fix * fix * fix * fix * use enum value
1 parent 1e8f6e9 commit 89db65a

4 files changed

Lines changed: 38 additions & 22 deletions

File tree

packages/modules/internal_chargepoint_handler/clients.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from typing import List, NamedTuple, Optional, Tuple, Union
44
from helpermodules.logger import ModifyLoglevelContext
5+
from modules.chargepoints.internal_openwb.config import InternalChargepointMode
56
from modules.common.fault_state import FaultState
67
from modules.common.hardware_check import SeriesHardwareCheckMixin
78

@@ -24,8 +25,10 @@
2425
CP1_METERS = [meter_config(mpm3pm.Mpm3pm, modbus_id=6), meter_config(sdm.Sdm630_72, modbus_id=106)]
2526

2627
EVSE_ID_CP0 = [1]
28+
EVSE_ID_SE_CP0 = [11]
2729
EVSE_ID_TWO_BUSSES_CP1 = [1, 2]
2830
EVSE_ID_ONE_BUS_CP1 = [2]
31+
EVSE_ID_ONE_BUS_SE_CP1 = [12]
2932
EVSE_MIN_FIRMWARE = 7
3033

3134

@@ -91,15 +94,17 @@ def get_pins_cp_interruption(self) -> int:
9194
return 15
9295

9396

94-
def client_factory(local_charge_point_num: int,
97+
def client_factory(mode: InternalChargepointMode,
98+
local_charge_point_num: int,
9599
fault_state: FaultState,
96100
created_client_handler: Optional[ClientHandler] = None) -> ClientHandler:
97101
serial_client, evse_ids = get_modbus_client(
98-
local_charge_point_num, created_client_handler, fault_state)
102+
mode, local_charge_point_num, created_client_handler, fault_state)
99103
return ClientHandler(local_charge_point_num, serial_client, evse_ids, fault_state)
100104

101105

102-
def get_modbus_client(local_charge_point_num: int,
106+
def get_modbus_client(mode: InternalChargepointMode,
107+
local_charge_point_num: int,
103108
created_client_handler: Optional[ClientHandler] = None,
104109
fault_state: Optional[FaultState] = None) -> Tuple[Union[ModbusSerialClient_, ModbusTcpClient_],
105110
List[int]]:
@@ -120,7 +125,10 @@ def get_modbus_client(local_charge_point_num: int,
120125
with ModifyLoglevelContext(log, logging.DEBUG):
121126
log.debug("LP0 Device: "+str(resolved_devices[0]))
122127
serial_client = ModbusSerialClient_(resolved_devices[0])
123-
evse_ids = EVSE_ID_CP0
128+
if mode == InternalChargepointMode.SE:
129+
evse_ids = EVSE_ID_SE_CP0
130+
else:
131+
evse_ids = EVSE_ID_CP0
124132
else:
125133
# Don't create two clients for one source!
126134
with ModifyLoglevelContext(log, logging.DEBUG):
@@ -129,7 +137,10 @@ def get_modbus_client(local_charge_point_num: int,
129137
serial_client = created_client_handler.client
130138
else:
131139
serial_client = ModbusSerialClient_(resolved_devices[0])
132-
evse_ids = EVSE_ID_ONE_BUS_CP1
140+
if mode == InternalChargepointMode.SE:
141+
evse_ids = EVSE_ID_ONE_BUS_SE_CP1
142+
else:
143+
evse_ids = EVSE_ID_ONE_BUS_CP1
133144
elif counter > 1:
134145
with ModifyLoglevelContext(log, logging.DEBUG):
135146
log.debug("found "+str(counter)+" possible usb devices: "+str(resolved_devices))

packages/modules/internal_chargepoint_handler/internal_chargepoint_handler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,21 @@ def __init__(self,
106106
try:
107107
with SingleComponentUpdateContext(self.fault_state_info_cp0, reraise=True):
108108
# Allgemeine Fehlermeldungen an LP 1:
109-
if mode == InternalChargepointMode.PRO_PLUS.value:
109+
if mode == InternalChargepointMode.PRO_PLUS:
110110
self.cp0_client_handler = None
111111
else:
112-
self.cp0_client_handler = client_factory(0, self.fault_state_info_cp0)
112+
self.cp0_client_handler = client_factory(mode, 0, self.fault_state_info_cp0)
113113
self.cp0 = HandlerChargepoint(self.cp0_client_handler, 0, mode,
114114
global_data, parent_cp0, hierarchy_id_cp0)
115115
except Exception:
116116
self.cp0_client_handler = None
117117
self.cp0 = None
118118
try:
119-
if ((mode == InternalChargepointMode.DUO.value or mode == InternalChargepointMode.SE.value) and
119+
if ((mode == InternalChargepointMode.DUO or mode == InternalChargepointMode.SE) and
120120
hierarchy_id_cp0 is not None):
121121
with SingleComponentUpdateContext(fault_state_info_cp1, reraise=True):
122122
log.debug("Zweiter Ladepunkt für Duo konfiguriert.")
123-
self.cp1_client_handler = client_factory(1, fault_state_info_cp1, self.cp0_client_handler)
123+
self.cp1_client_handler = client_factory(mode, 1, fault_state_info_cp1, self.cp0_client_handler)
124124
self.cp1 = HandlerChargepoint(self.cp1_client_handler, 1, mode,
125125
global_data, parent_cp1, hierarchy_id_cp1)
126126
else:
@@ -163,7 +163,7 @@ def _loop():
163163
time.sleep(1.1)
164164
with SingleComponentUpdateContext(self.fault_state_info_cp0, update_always=False):
165165
# Allgemeine Fehlermeldungen an LP 1
166-
if self.cp0 is not None and self.cp0.mode == InternalChargepointMode.PRO_PLUS.value:
166+
if self.cp0 is not None and self.cp0.mode == InternalChargepointMode.PRO_PLUS:
167167
_loop()
168168
elif self.cp0_client_handler is None and self.cp1_client_handler is None:
169169
log.error("Kein ClientHandler vorhanden. Beende.")
@@ -195,9 +195,9 @@ def __init__(self,
195195
self.local_charge_point_num = local_charge_point_num
196196
self.mode = mode
197197
if local_charge_point_num == 0:
198-
if mode == InternalChargepointMode.SOCKET.value:
198+
if mode == InternalChargepointMode.SOCKET:
199199
self.module = Socket(local_charge_point_num, client_handler, internal_cp, hierarchy_id)
200-
elif mode == InternalChargepointMode.PRO_PLUS.value:
200+
elif mode == InternalChargepointMode.PRO_PLUS:
201201
self.module = ProPlus(local_charge_point_num, internal_cp, hierarchy_id)
202202
else:
203203
self.module = chargepoint_module.ChargepointModule(
@@ -257,7 +257,7 @@ def handler(self):
257257
hierarchy_id_cp1 = None
258258
for cp in SubData.cp_data.values():
259259
if cp.chargepoint.chargepoint_module.config.type == "internal_openwb":
260-
mode = cp.chargepoint.chargepoint_module.config.configuration.mode
260+
mode = InternalChargepointMode(cp.chargepoint.chargepoint_module.config.configuration.mode)
261261
if cp.chargepoint.chargepoint_module.config.configuration.duo_num == 0:
262262
hierarchy_id_cp0 = cp.chargepoint.num
263263
else:

runs/evse_read_modbus.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#!/usr/bin/env python3
2+
from pathlib import Path
23
import sys
4+
5+
36
sys.path.append("/var/www/html/openWB/packages")
47
try:
5-
from modules.internal_chargepoint_handler.clients import get_modbus_client
6-
from modules.common.modbus import ModbusDataType
8+
from modules.common.modbus import ModbusDataType, ModbusSerialClient_
79
except Exception as e:
810
# Durch try-except werden die Imports vom Formatierer nicht an den Dateianfang geschoben.
911
print(e)
1012

11-
local_chargepoint_num = int(sys.argv[1])
13+
unit = int(sys.argv[1])
1214
register = int(sys.argv[2])
1315
num = int(sys.argv[3])
1416

15-
client, evse_ids = get_modbus_client(local_chargepoint_num)
16-
print(client.read_holding_registers(register, [ModbusDataType.INT_16]*num, unit=evse_ids[0]))
17+
client = ModbusSerialClient_(str(list(Path("/dev/serial/by-path").glob("*"))[0].resolve()))
18+
print(client.read_holding_registers(register, [ModbusDataType.INT_16]*num, unit=unit))

runs/evse_write_modbus.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#!/usr/bin/python3
2+
from pathlib import Path
23
import sys
4+
5+
36
sys.path.append("/var/www/html/openWB/packages")
47
try:
5-
from modules.internal_chargepoint_handler.clients import get_modbus_client
8+
from modules.common.modbus import ModbusSerialClient_
69
except Exception as e:
710
# Durch try-except werden die Imports vom Formatierer nicht an den Dateianfang geschoben.
811
print(e)
912

10-
local_chargepoint_num = int(sys.argv[1])
13+
unit = int(sys.argv[1])
1114
register = int(sys.argv[2])
1215
value = int(sys.argv[3])
1316

14-
client, evse_ids = get_modbus_client(local_chargepoint_num)
15-
client.write_registers(register, value, unit=evse_ids[0])
17+
client = ModbusSerialClient_(str(list(Path("/dev/serial/by-path").glob("*"))[0].resolve()))
18+
client.write_register(register, value, unit=unit)

0 commit comments

Comments
 (0)