Open Hooorny opened 3 days ago
Nice. I was currently checking the Jkbms_can driver and saw a few question marks there.
Thanks for checking.
JKBMS_CAN_CELL_COUNT
constant. If you get the cells. then please do not use this constant. I'm reworking the other driver to remove it.For the new JKBMS_PB_CAN_DEVICE_ADDRESSES =
please remove it and use the MODBUS_ADDRESSES
constant. I will rename it to DEVICE_ADDRESSES
later, so it can be used for both.
Do you have a protocol documentation which you can post here?
What for a protocol have you selected in the JKBMS app for the CAN port?
I can reuse the MODBUS_ADDRESSES
but then you can't mix CAN and Modbus ... dont know if someone would do this ;)
I found the original protocol spec here http://www.jk-bms.com/en/Upload/2023-12-05/1559288117.pdf and translated it to german with ChatGPT. JK_BMS_CAN_Spezifikationen.pdf
In the JK BMS App both entries work according to what is configured as CAN_SPEED
in config.ini
I committed a thread safe implementation of a CanReceiverThread handling CAN-BUS communication ... seems working for me. Unfortunately i have a ERROR:SerialBattery:Non blocking exception occurred: KeyError('/CurrentAvg') of type <class 'KeyError'> in /opt/victronenergy/dbus-serialbattery/dbushelper.py line 989 in the logs, but cant find a dependency to my commit
hmmm, the error came from the changes in jkbms_pb_can.py ... i need further investigation whats going on here.
It also works for my JKBMS, which is no PB model. Very nice!
In my opinion the CanReceiverThread
should be started as soon as possible and directly in dbus-serialbattery.py
after expected_bms_types
. Each battery instance (which are added directly after) then should only get data from the CAN cache and search for the correct data.
In the test_connection()
function we need to check as fast as possible, if the BMS driver matches the BMS and return as fast as possible false, if they are not matching. --> Done
If they match, we have more time. We need to get all the needed data to correctly start the driver. In the protocol documentation the slowest data cycles are the cell voltages. Therefore I would wait a bit more than 1 second before continuing with the start of the driver, so that we received all data at least once. This permit us to remove the JKBMS_CAN_CELL_COUNT
from the config file. --> Done
I fixed the KeyError('/CurrentAvg') bug, which raised in your case, because not all values were loaded on driver startup.
I pushed the changes to your branch.
This is not working as expected. Maybe you have a better idea https://github.com/mr-manuel/venus-os_dbus-serialbattery/pull/108/commits/7c21c4fa4dfb573b92b8107a544e6a0935e442ae
Very cool changes!
I extracted the CanReceiver class to a new file, which is only imported by CAN BMS, I think this is the cleanest solution.
In my opinion the CanReceiverThread should be started as soon as possible and directly in dbus-serialbattery.py after expected_bms_types. Each battery instance (which are added directly after) then should only get data from the CAN cache and search for the correct data.
Thats the way it is working. The first battery makes an instance which is a singleton for the "channel, bustype, bitrate" tuple, all following batteries with the same tuple will get the same instance, so they all share the same bus listener. I dont know if the port (can1 at my CerboGX) is the same for the second BMS-CAN jack
Runs very smooth so far :)
I just figured out, that the device address is configured by the dip switches and not in the JK BMS App. Seems to be the same as for RS485
Indeed it's cleaner now. Thanks.
I still would prefer to have self.can_thread = CanReceiverThread.get_instance(bustype=self.CAN_BUS_TYPE, channel=self.port, bitrate=self.baud_rate)
in the dbus-serialbattery.py
before testing the different batteries. Why? Because else every battery driver test in the future will maybe wait some seconds that all frames are send, which is not needed on a battery driver base, but on a common base. Also on the same CAN bus port all devices have the same "channel, bustype, bitrate".
I dont know if the port (can1 at my CerboGX) is the same for the second BMS-CAN jack
I tried to connect it to the BMS-CAN and it also works, but the JK BMS CAN Protocol (500K) V2.0
has to be selected. There would be a workaround to set it also to 250k, but it's not worth the effort.
I just figured out, that the device address is configured by the dip switches and not in the JK BMS App. Seems to be the same as for RS485
Really strange, as always from JKBMS. On my BMS I have no dip switches, so it seems to be only possible with the JKBMS PB Model. Maybe it works at some point with newer BMSes in the future, if anyone reaches JKBMS to tell them that.
I currently used one of the 2 BMS-CAN Ports at the CerboGX with the 500k JK Protocol, both ports are listed under "can1" using canshow. The 2 VE-CAN Ports show up as "can0" ... so I may connect 2 BMS to the same CAN-Port "can0" or "can1". Perhaps its also possible to daisy chain further BMS via RS485 and only use the master for CAN connection ... ?! Would be interesting if the other BMS will be on CAN with different frame ids