Let us now take a look at the DBC database we just created. We start by just printing the contents from Python:
import textwrap
from canlib import kvadblib
with kvadblib .Dbc( filename=’db_histogram . dbc ’ ) as db:
print (db)
for message in db:
print ( ’\n {} ’ . format(message) )
for signal in message :
print (textwrap . f i l l ( ’ {} ’ . format( signal ) , 80))
The textwrap module is used here to get a nice width of 80 characters on the printout:
Dbc db_histogram: flags:0, protocol:CAN, messages:4
Message(name=’LIM_002’, id=402, flags=<MessageFlag.0: 0>, dlc=8, comment=’’)
Signal(name=’Load’, type=<SignalType.FLOAT: 3>,
byte_order=<SignalByteOrder.INTEL: 0>, mode=-1, size=ValueSize(startbit=0,
length=32), scaling=ValueScaling(factor=1.0, offset=0.0),
limits=ValueLimits(min=0.0, max=100.0), unit=’metric ton’, comment=’Measured
load in system.’)
Message(name=’ECM_004’, id=504, flags=<MessageFlag.0: 0>, dlc=8, comment=’’)
Signal(name=’Fuel’, type=<SignalType.FLOAT: 3>,
byte_order=<SignalByteOrder.INTEL: 0>, mode=-1, size=ValueSize(startbit=0,
length=32), scaling=ValueScaling(factor=1.0, offset=0.0),
limits=ValueLimits(min=0.0, max=300.0), unit=’l/100 km’, comment=’Current fuel
consumption.’)
Message(name=’ECM_003’, id=503, flags=<MessageFlag.0: 0>, dlc=8, comment=’’)
Signal(name=’EngineTemp’, type=<SignalType.FLOAT: 3>,
byte_order=<SignalByteOrder.INTEL: 0>, mode=-1, size=ValueSize(startbit=0,
length=32), scaling=ValueScaling(factor=1.0, offset=0.0),
limits=ValueLimits(min=-60.0, max=200.0), unit=’Celsius’, comment=’System
temperature consumption.’)
Message(name=’ECM_001’, id=501, flags=<MessageFlag.0: 0>, dlc=8, comment=’’)
Signal(name=’EngineSpeed’, type=<SignalType.UNSIGNED: 2>,
byte_order=<SignalByteOrder.INTEL: 0>, mode=-1, size=ValueSize(startbit=0,
length=32), scaling=ValueScaling(factor=1.0, offset=0.0),
limits=ValueLimits(min=0.0, max=6000.0), unit=’rpm’, comment=’Current engine
speed.’)
Hopefully there were no surprises there, so let us finish this part of this blog series by also see how our database looks in the Kvaser Database Editor.
Figure 1: Looking at our newly created database in the Kvaser Database Editor.
In the middle panel of Kvaser Database Editor, we can see our four defined messages. In Figure 1, the message “LIM_002” is selected and the content of the message is shown below the message. In our case we have a single signal named “Load” with e.g. unit set to “metric ton”. In the right pane, a layout (with shadowed cells) of the current messsage’s data bits is shown. In Figure 1, we can see that the selected signal spans from bit 0 in the first byte through bit 7 in the third byte, this corresponds to the start position 0 and length 32 that was given.
Thus ends our first part which described how to create a database. In the next part we will take a look at how use the database while sending and receiving signals