Search code examples
pythonfilteringprotocolscan-bus

Python-Can Bus, grab only the bytes?


Require some help with Python-can. At the moment, my code is just receiving data with a 2 second delay so the shell doesn't flood itself.

How do i filter the information, just so I can use the bytes received to interpret the information? At the moment its giving me everything.

import can
import time

bus = can.interface.Bus(bustype='nican', channel='CAN0', bitrate=1000000)

recvMsg = bus.recv(timeout=None)
while(recvMsg is not None):
    print (recvMsg.)
    time.sleep(2)
else:
    print ("None")

Solution

  • Please have a look at the message type of python-can.

    Examples:

    If you want to print the number of bytes in the data field, use

    print(recvMsg.dlc)
    

    If you want to print the first data byte, use

    print(recvMsg.data[0])