Skip to content

Conversation

@marcelrv
Copy link
Contributor

@marcelrv marcelrv commented Sep 4, 2025

Avoid not proper handled TypeError: 'NoneType' object is not subscriptable

@4000000068b973dd1eb993e4 ERROR:SerialBattery:Exception occurred: OSError(71, 'Protocol error') of type <class 'OSError'> in /data/apps/dbus-serialbattery/utils.py line #831
@4000000068b973dd21464d8c Traceback (most recent call last):
@4000000068b973dd232fd5dc   File "/data/apps/dbus-serialbattery/dbushelper.py", line 781, in publish_battery
@4000000068b973dd232ff134     result = self.battery.refresh_data()
@4000000068b973dd232ffcec              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@4000000068b973dd2332008c   File "/data/apps/dbus-serialbattery/bms/jkbms_pb.py", line 173, in refresh_data
@4000000068b973dd23321414     return self.read_status_data()
@4000000068b973dd23321fcc            ^^^^^^^^^^^^^^^^^^^^^^^
@4000000068b973dd2332279c   File "/data/apps/dbus-serialbattery/bms/jkbms_pb.py", line 176, in read_status_data
@4000000068b973dd23323b24     status_data = self.read_serial_data_jkbms_pb(self.command_status, 299)
@4000000068b973dd23324ac4                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@4000000068b973dd2333aa54   File "/data/apps/dbus-serialbattery/bms/jkbms_pb.py", line 368, in read_serial_data_jkbms_pb
@4000000068b973dd2333bddc     if data[0] == 0x55 and data[1] == 0xAA:
@4000000068b973dd2333c994        ~~~~^^^
@4000000068b973dd2335adf4 TypeError: 'NoneType' object is not subscriptable

Avoid not proper handled `TypeError: 'NoneType' object is not subscriptable`


```
@4000000068b973dd1eb993e4 ERROR:SerialBattery:Exception occurred: OSError(71, 'Protocol error') of type <class 'OSError'> in /data/apps/dbus-serialbattery/utils.py line #831
@4000000068b973dd21464d8c Traceback (most recent call last):
@4000000068b973dd232fd5dc   File "/data/apps/dbus-serialbattery/dbushelper.py", line 781, in publish_battery
@4000000068b973dd232ff134     result = self.battery.refresh_data()
@4000000068b973dd232ffcec              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@4000000068b973dd2332008c   File "/data/apps/dbus-serialbattery/bms/jkbms_pb.py", line 173, in refresh_data
@4000000068b973dd23321414     return self.read_status_data()
@4000000068b973dd23321fcc            ^^^^^^^^^^^^^^^^^^^^^^^
@4000000068b973dd2332279c   File "/data/apps/dbus-serialbattery/bms/jkbms_pb.py", line 176, in read_status_data
@4000000068b973dd23323b24     status_data = self.read_serial_data_jkbms_pb(self.command_status, 299)
@4000000068b973dd23324ac4                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@4000000068b973dd2333aa54   File "/data/apps/dbus-serialbattery/bms/jkbms_pb.py", line 368, in read_serial_data_jkbms_pb
@4000000068b973dd2333bddc     if data[0] == 0x55 and data[1] == 0xAA:
@4000000068b973dd2333c994        ~~~~^^^
@4000000068b973dd2335adf4 TypeError: 'NoneType' object is not subscriptable

```
@marcelrv
Copy link
Contributor Author

marcelrv commented Sep 4, 2025

Note that there are 2 more places with similar check that prob needs to be fixed.
But have not seen them popping in my error log yet. Maybe now I have this fix in place, they will appear

@mr-manuel
Copy link
Owner

Thanks for helping to improve this driver! Do you want to further test this before I merge it?

@marcelrv
Copy link
Contributor Author

marcelrv commented Sep 6, 2025

The log is much cleaner with these fixes.
As it is anyway aan improvement over the original code, suggest to merge it.

From the comments In the code it seems like the crc is bypasses. As i occasionally see odd values and saw also message about exceeding values i will take a look if I can get proper crc checking in place.
That will be separate pr through and may take a while

@mr-manuel
Copy link
Owner

Sounds great, thanks!

@marcelrv
Copy link
Contributor Author

marcelrv commented Sep 6, 2025

e.g. here is my logging now when error occurs:
ignore the INFO:SerialBattery:no data catch this is some additional loggin I added to track when the issue would have been triggered.

So with this change it seems to properly catch the 'False' that comes from utils.py read_serial_data returning False

@4000000068b9eaaa1e6b25c4 INFO:SerialBattery:Battery JKBMS PB Model connected to dbus from /dev/ttyUSB0
@4000000068b9eaaa1e6b3564 INFO:SerialBattery:========== Settings ==========
@4000000068b9eaaa1e6b411c INFO:SerialBattery:> Connection voltage: 52.558 V | Current: 0.0 A | SoC: 37%
@4000000068b9eaaa1e6b50bc INFO:SerialBattery:> Cell count: 16 | Cells populated: 16
@4000000068b9eaaa1e6bc204 INFO:SerialBattery:> CHARGE MODE: Linear
@4000000068b9eaaa1e6bcdbc INFO:SerialBattery:> MIN CELL VOLTAGE: 2.900 V | MAX CELL VOLTAGE: 3.450 V| FLOAT CELL VOLTAGE: 3.375 V
@4000000068b9eaaa1e6becfc INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 250.0 A | MAX BATTERY DISCHARGE CURRENT: 160.0 A
@4000000068b9eaaa1e6c0084 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 100.0 A | MAX BATTERY DISCHARGE CURRENT: 200.0 A (read from BMS)
@4000000068b9eaaa1e6c69fc INFO:SerialBattery:> CVCM:       True
@4000000068b9eaaa1e6c799c INFO:SerialBattery:> CCCM CV:    True  | DCCM CV:       True
@4000000068b9eaaa1e6c910c INFO:SerialBattery:> CCCM T:     True  | DCCM T:        True
@4000000068b9eaaa1e6c9cc4 INFO:SerialBattery:> CCCM T MOS: True  | DCCM T MOS:    True
@4000000068b9eaaa1e6cb04c INFO:SerialBattery:> CCCM SOC:   False | DCCM SOC:      False
@4000000068b9eaaa1e6d257c INFO:SerialBattery:> CHARGE FET: 1     | DISCHARGE FET: 1 | BALANCE FET: True
@4000000068b9eaaa1e6df09c INFO:SerialBattery:Serial Number/Unique Identifier: 41216494742
@4000000068ba603a322a376c ERROR:SerialBattery:Exception occurred: OSError(71, 'Protocol error') of type <class 'OSError'> in /data/apps/dbus-serialbattery/utils.py line #831
@4000000068ba603a325c6afc INFO:SerialBattery:no data catch
@4000000068ba864d24c886dc ERROR:SerialBattery:Exception occurred: OSError(71, 'Protocol error') of type <class 'OSError'> in /data/apps/dbus-serialbattery/utils.py line #831
@4000000068ba864d24faaeb4 INFO:SerialBattery:no data catch
@4000000068baaf6c23df8a54 ERROR:SerialBattery:Exception occurred: OSError(75, 'Value too large for defined data type') of type <class 'OSError'> in /data/apps/dbus-serialbattery/utils.py li
@4000000068baaf6c24012bb4 INFO:SerialBattery:no data catch
@4000000068babafc2616d0fc ERROR:SerialBattery:Exception occurred: OSError(71, 'Protocol error') of type <class 'OSError'> in /data/apps/dbus-serialbattery/utils.py line #831
@4000000068babafc26195584 INFO:SerialBattery:no data catch

@mr-manuel mr-manuel merged commit d736c04 into mr-manuel:master Sep 14, 2025
2 checks passed
mr-manuel pushed a commit that referenced this pull request Sep 29, 2025
JKBMS PB: Refactor condition to check for missing data
cgoudie pushed a commit to TechBlueprints/venus-os_dbus-serialbattery that referenced this pull request Nov 4, 2025
JKBMS PB: Refactor condition to check for missing data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants