我该如何解决这个问题? Python 关于 id 的 cantools 键错误
how can i solve this? Python cantools key error regarding id
我正在尝试通过 cantools
解码 can 消息。
for ii in range(len(dbcfiles)):
databases.append(cantools.db.load_file(dbcfiles[ii]))
db = cantools.db.Database()
for database in databases:
db.messages.extend(database.messages)
decoded_mess = []
with can.BLFReader(logfile) as can_log:
for msg in can_log:
print(msg.data)
print(db.decode_message(msg.arbitration_id, msg.data))
print(msg)
# Timestamp: 1610115116.731417 ID: 0036 S DLC: 8 c0 08 7e 08 a9 0d 0b 0f Channel: 24
问题是最后一行 db.decode_message(msg.arbitration_id, msg.data)
产生了 Key Error: 54 (thats decimal of 36)
。我收到不同 ID 的每个消息的错误,我知道 ID 在 dbc 中。
第二次 for 循环调用后
db.refresh()
来自 cantools 文档:
refresh()
Refresh the internal database state.
This method must be called after modifying any message in the database to refresh the internal lookup tables used when encoding and decoding messages.
我正在尝试通过 cantools
解码 can 消息。
for ii in range(len(dbcfiles)):
databases.append(cantools.db.load_file(dbcfiles[ii]))
db = cantools.db.Database()
for database in databases:
db.messages.extend(database.messages)
decoded_mess = []
with can.BLFReader(logfile) as can_log:
for msg in can_log:
print(msg.data)
print(db.decode_message(msg.arbitration_id, msg.data))
print(msg)
# Timestamp: 1610115116.731417 ID: 0036 S DLC: 8 c0 08 7e 08 a9 0d 0b 0f Channel: 24
问题是最后一行 db.decode_message(msg.arbitration_id, msg.data)
产生了 Key Error: 54 (thats decimal of 36)
。我收到不同 ID 的每个消息的错误,我知道 ID 在 dbc 中。
第二次 for 循环调用后
db.refresh()
来自 cantools 文档:
refresh() Refresh the internal database state.
This method must be called after modifying any message in the database to refresh the internal lookup tables used when encoding and decoding messages.