How to Decode Message from a Canbus (Iptronik)

I retrieve from a canbus the following message and signal data (from an Iptronik sim stg machine). I coded it with python, I use the python-can library and I have ubuntu 18.04

The message /signal retrieved :

Timestamp: 1570622811.311113        ID: 0060    S                DLC:  8    e4 7f 55 55 55 55 04 00     Channel: can0
Timestamp: 1570622811.811173        ID: 0060    S                DLC:  8    e4 7f 55 55 55 55 0f 06     Channel: can0
Timestamp: 1570622812.311224        ID: 0060    S                DLC:  8    e4 7f 55 55 55 55 65 1a     Channel: can0
Timestamp: 1570622812.811266        ID: 0060    S                DLC:  8    e4 7f 55 55 55 55 47 0c     Channel: can0
Timestamp: 1570622813.311266        ID: 0060    S                DLC:  8    e4 7f 55 55 55 55 2c 58     Channel: can0
Timestamp: 1570622813.811316        ID: 0060    S                DLC:  8    e4 7f 55 55 55 55 20 36     Channel: can0

from the dbc file I have this information.

BO_ 96 DEVICE_51900450_0: 8 C_51900450
  SG_ Beschleunigung : 0|16@1+ (0.000152590218966964,-5) [-5|5] "V" IPETRONIK_CAN_1
  SG_ Pos : 48|16@1+ (0.000152590218966964,0) [0|10] "V" IPETRONIK_CAN_1

when I convert to the 4 first bits and the four last one I get this number that does not correspond to the dbc file .

(228, 127, 3, 0)
(228, 127, 3, 0)
(228, 127, 62, 3)
(228, 127, 162, 16)
(228, 127, 143, 28)
(228, 127, 252, 93)

Can you help me or give me some advice to convert properly the signal according to the dbc instructions. Thank you in advance :)

3 Answers

this might help you...

import cantools
import can
from pprint import pprint 

db = cantools.database.load_file('******_dbc.dbc') #path of .dbc file
print( db.messages)
can_bus = can.interface.Bus('can0', bustype='socketcan')
message = can_bus.recv()
for msg in can_bus:
     print ( db.decode_message(msg.arbitration_id, msg.data))

You may use CAN BUS tools () to load your .DBC file and properly decode your CAN messages:

pip install cantools

Here's the sample code:

>>> import cantools
>>> from pprint import pprint
>>> db = cantools.database.load_file('tests/files/dbc/motohawk.dbc')
>>> db.messages
[message('ExampleMessage', 0x1f0, False, 8, 'Example message used as template in MotoHawk models.')]
>>> example_message = db.get_message_by_name('ExampleMessage')
>>> pprint(example_message.signals)
[signal('Enable', 7, 1, 'big_endian', False, 1.0, 0, 0.0, 0.0, '-', False, None, {0: 'Disabled', 1: 'Enabled'}, None),
 signal('AverageRadius', 6, 6, 'big_endian', False, 0.1, 0, 0.0, 5.0, 'm', False, None, None, ''),
 signal('Temperature', 0, 12, 'big_endian', True, 0.01, 250, 229.53, 270.47, 'degK', False, None, None, None)]
1

In python there is this awesome library

You can go through the source code of it to find the fields you need to extract :

All relevant fields for messages and signals can be found out in cantools/database/can/message.py and /database/can/signal.py in this github link

For eg: if you need names and unit of signals you could use signal.name and signal.unit

Sample code to extract these fields:

 #**dbc_file** is the full path of dbc 
    db = cantools.database.load_file(dbc_file)
    for msg in db.messages:
        msg_name = msg.name
        msg_id = msg.frame_id
        msg_length = msg.length
        sender = msg.senders
        msg_group = db.get_message_by_name(msg_name)
    
        for signal in msg_group.signals:
            
            #name of signal
            sig_name = signal.name
            #unit of signal
            sig_unit = signal.unit

Hope this might help some one!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest