I am trying to decode CAN messages from a device using the manufacturer's provided dbc file. I am using Python 3.8.5. To load/set up the dbc file, I have:
import can
import cantools
self.bus = can.interface.Bus('slcan0', bustype='socketcan',bitrate=250000)
listener = can.Listener()
listener.on_message_received = self.callback
self.dbc = cantools.database.load_file(dbc_file_path,strict=False) #need strict=False or it raises errors for overlapping signals for some reason
in the callback function I have:
def callback(self, can_msg):
decoded = self.dbc.decode_message(can_msg.arbitration_id, can_msg.data)
The script runs, but as soon as it receives a CAN message from the device, it gives me the following error:
Traceback (most recent call last):
File "/home/.local/lib/python3.8/site-packages/cantools/database/can/database.py", line 385, in decode_message
message = self._frame_id_to_message[frame_id_or_name]
KeyError: 392
Any idea what might be going wrong? I have googled and found similar errors on stack overflow, but they don't seem to be exactly the same, and the solutions they propose don't fix my issue.
Thanks!
question from:
https://stackoverflow.com/questions/66051065/keyerror-392-upon-trying-to-decode-can-message-using-dbc-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…