Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Heltec BMS breaks on other ModBus BMS connection tests #672

Merged
merged 1 commit into from
May 26, 2023
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
4 changes: 3 additions & 1 deletion etc/dbus-serialbattery/bms/heltecmodbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def read_status_data(self):
mbdev = mbdevs[self.address]

with locks[self.address]:
for n in range(1, RETRYCNT):
for n in range(1, RETRYCNT + 1):
try:
ccur = mbdev.read_register(191, 0, 3, False)
self.max_battery_charge_current = (
Expand Down Expand Up @@ -223,6 +223,8 @@ def read_status_data(self):
+ "): "
+ str(e)
)
if n == RETRYCNT:
return False
continue

logger.info(self.hardware_version)
Expand Down
2 changes: 1 addition & 1 deletion etc/dbus-serialbattery/config.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ TIME_TO_SOC_INC_FROM = False


; --------- Additional settings ---------
; Specify only one BMS type to load else leave empty to try to load all availabe
; Specify only one BMS type to load else leave empty to try to load all available
; LltJbd, Ant, Daly, Daly, Jkbms, Lifepower, Renogy, Renogy, Ecs
BMS_TYPE =

Expand Down
27 changes: 17 additions & 10 deletions etc/dbus-serialbattery/dbus-serialbattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,24 @@ def get_battery(_port) -> Union[Battery, None]:
while count > 0:
# create a new battery object that can read the battery and run connection test
for test in expected_bms_types:
logger.info("Testing " + test["bms"].__name__)
batteryClass = test["bms"]
baud = test["baud"]
battery: Battery = batteryClass(
port=_port, baud=baud, address=test.get("address")
)
if battery.test_connection():
logger.info(
"Connection established to " + battery.__class__.__name__
# noinspection PyBroadException
try:
logger.info("Testing " + test["bms"].__name__)
batteryClass = test["bms"]
baud = test["baud"]
battery: Battery = batteryClass(
port=_port, baud=baud, address=test.get("address")
)
return battery
if battery.test_connection():
logger.info(
"Connection established to " + battery.__class__.__name__
)
return battery
except KeyboardInterrupt:
return None
except Exception:
# Ignore any malfunction test_function()
pass
count -= 1
sleep(0.5)

Expand Down