查询文档后编写代码如下
import can
import cantools
db = cantools.database.load_file("xxx.dbc")
def send_one(msg_id, data):
msg = db.get_message_by_frame_id(msg_id)
_data = {_.name:0 for _ in msg.signals}
_data.update(data)
msg_data = msg.encode(_data)
print(msg_data, msg.frame_id)
message = can.Message(arbitration_id=msg_id, data=msg_data)
bus = can.Bus(interface='vector', app_name='CANalyzer', channel=0, bitrate=500000)
# bus.set_application_config("Configuration0.cfg")
# bus.
print(dir(bus))
try:
bus.send(message)
print(f"Message sent on {bus.channel_info}")
except can.CanError:
print("Message NOT sent")
bus.shutdown()
if __name__ == "__main__":
# send_one()
send_one(0x3d8,{"xxx": 0x1, "xxx": 0x01, "xxx": 0x01})
运行之后提示发送成功,但是实际上我在canalyzer面板上并没有看到消息的信号值发生变化,请问这里该怎么做才能是真的发送成功?