I am trying to use Python CAN, with Vector CAN interface to implement sending cyclic messages to an actual ECU. The message I am sending let's call it TorqueDemandMsg
, it has 4 bit rolling counter MsgCounter
as one of the signal, so that the ECU knows the message is up to date. Currently in main, I set up a cyclic broadcast task with defined period using Python CAN.
To increment the counter, I have to explicitly call a class method i created updateCounter
to update MsgCounter
, and use can.modify_data(message)
method in Python CAN to update the message.
The problem is when I call the class method to update MsgCounter
, it is desync from the actual cyclic message scheduled by the can.send_periodic(message)
This leads to cases like this in the actual output on CAN bus (only showing MsgCounter signal here)
time 0: 0
time 0.1: 1
time 0.2: 2
time 0.3: 3
time 0.4: 3
time 0.5: 4
time 0.6: 6
.....
It can either still use old value or skip value, based on how main()
calls the updateCounter
.
Is there a way to modify the signal value, in sync with the schedule broadcast, handled by the the class object itself?
relevant Python CAN document: https://python-can.readthedocs.io/en/master/bcm.html?highlight=modify_data