dbc

dbc manipulation: editing and creating dbc files
db = cantools.database.load_file('../res/motohawk_new.dbc')
db.messages
example_message: MessageTpl = db.get_message_by_name('ExampleMessage')
pprint(example_message.signals)
pprint(example_message.__dict__)
example_message.frame_id

Following show how to create a new dbc file from scratch using cantools

can_id = example_message.frame_id + 10
can_id
can_db = cantools.db
db_new = cantools.database.Database(version='0.1')
sig = can_db.Signal(name="torque_table", 
                    start=0, 
                    length=8, 
                    byte_order='big_endian', 
                    is_signed=False, 
                    minimum=0, 
                    maximum=255, 
                    unit='Nm',
                    comment="self made signal",
                    is_multiplexer=False)

msg = can_db.Message(frame_id=can_id,
                    name="NewMessage",
                    signals=[sig],
                    length=8,
                    is_extended_frame=False,
                    is_fd=False,
                    comment="self made message",
                    send_type=0,
                    cycle_time=0,
                    bus_name="PT",
                    )

db_new.messages.append(msg)
# can_db.add_message(msg)
cantools.database.dump_file(database=db_new,filename='test.dbc')
# db.dump('test.dbc')

Following show how to append a new message to an existing dbc using cantools

can_id = example_message.frame_id + 200
can_db = cantools.db
db.version = '1.1'
sig = can_db.Signal(name="eco_table", 
                    start=0, 
                    length=8, 
                    byte_order='big_endian', 
                    is_signed=False, 
                    minimum=0, 
                    maximum=255, 
                    unit='Nm',
                    comment="self made signal",
                    is_multiplexer=False)

msg = can_db.Message(frame_id=can_id,
                    name="AppendedMessage",
                    signals=[sig],
                    length=8,
                    is_extended_frame=False,
                    is_fd=False,
                    comment="self made message",
                    send_type=0,
                    cycle_time=0,
                    bus_name="PT",
                    )

db.messages.append(msg)
# can_db.add_message(msg)
cantools.database.dump_file(database=db,filename='../res/motohawk_appended.dbc')
# db.dump('test.dbc')