Search code examples
pythoncan-bus

cantools.database get the sending node of a message


I have a program where I need to know the CAN-node of a message, I get from a DBC. I read the DBC like this:

db_input = cantools.db.load_file(dbc_path,database_format='dbc',encoding=None,frame_id_mask=None,strict=True,cache_dir=None)

I get a specific message like this:

print(db_input.messages[0])

and output is:

message('HOURS', 0x18fee59e, True, 8, None)

However in the DBC the message has the according CAN-node:

BO_ 2566841758 HOURS: 8 Sensor3

DBC syntax is this:

BO_ <CAN-ID> <MessageName>: <MessageLength> <SendingNode>

Is it possible to get something like this?:

 message('HOURS', 0x18fee59e, True, 8, Sensor3)

PS. I have looked at the specific node and the output is:

node('Sensor3', None)

maybe the None is wrongly taken as the node input, but I couldn´t find were the node is inputted in the source-code of the cantools.database library https://cantools.readthedocs.io/en/latest/_modules/cantools/database.html


Solution

  • According to the doc you should be able to get the sender(s) with .senders:

    print(db_input.messages[0].senders)
    

    What you're printing is only the representation of the message (see __repr__ in my link). The message has more properties (_senders among others)