pythoncan-bussocketcan

How to write a command to produce canbus data in the perticular format?


I am writing a python program to produce canbus data in the following format.

<0x18eeff01> [8] 05 a0 be 1c 00 a0 a0 c0

I am using python-can library for this and trying to read message format as above. I couldn't figure out what is the first format <0x18eeff01> indicates? I don't know how I will produce that in the output.


try:
    for i in range(0,200):
        msg=bus.recv(timeout=1)
        print("------")
        data = "{} [{}]".format(msg.channel,msg.dlc)
        for i in range(0,msg.dlc):
            data += " {}".format(msg.data[i])
        print(data)
        #Timestamp, Prio, PGN,src,dest, len, data



except can.CanError:
    print ("error")
finally:
    bus.shutdown()
f.close()````

Following is the output of this code:

````[8] 05 a0 be 1c 00 a0 a0 c0````

How can I produce whole string of the data as mentioned earlier?

Solution

  • 0x18eeff01 is the arbitration id in hex form. You can get it with msg.arbitration_id. See here