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