= cantools.database.load_file('../res/motohawk_new.dbc')
db
db.messages= db.get_message_by_name('ExampleMessage')
example_message: MessageTpl
pprint(example_message.signals)
pprint(example_message.__dict__) example_message.frame_id
dbc
dbc manipulation: editing and creating dbc files
Following show how to create a new dbc file from scratch using cantools
= example_message.frame_id + 10
can_id can_id
= cantools.db
can_db = cantools.database.Database(version='0.1')
db_new = can_db.Signal(name="torque_table",
sig =0,
start=8,
length='big_endian',
byte_order=False,
is_signed=0,
minimum=255,
maximum='Nm',
unit="self made signal",
comment=False)
is_multiplexer
= can_db.Message(frame_id=can_id,
msg ="NewMessage",
name=[sig],
signals=8,
length=False,
is_extended_frame=False,
is_fd="self made message",
comment=0,
send_type=0,
cycle_time="PT",
bus_name
)
db_new.messages.append(msg)# can_db.add_message(msg)
=db_new,filename='test.dbc')
cantools.database.dump_file(database# db.dump('test.dbc')
Following show how to append a new message to an existing dbc using cantools
= example_message.frame_id + 200
can_id = cantools.db
can_db = '1.1'
db.version = can_db.Signal(name="eco_table",
sig =0,
start=8,
length='big_endian',
byte_order=False,
is_signed=0,
minimum=255,
maximum='Nm',
unit="self made signal",
comment=False)
is_multiplexer
= can_db.Message(frame_id=can_id,
msg ="AppendedMessage",
name=[sig],
signals=8,
length=False,
is_extended_frame=False,
is_fd="self made message",
comment=0,
send_type=0,
cycle_time="PT",
bus_name
)
db.messages.append(msg)# can_db.add_message(msg)
=db,filename='../res/motohawk_appended.dbc')
cantools.database.dump_file(database# db.dump('test.dbc')