need some example code

Issue #81 new
Tom created an issue

Hi there, not the best with python, was wondering if somebody could post some example code of waiting for a certain canbus message to be received from e.g. can0 and once that message is received to then send data on can1.


Comments (2)

  1. Travis Travelstead

    Hello Tom,

    There is two main ways to approach this. You can use the SocketCAN level (kernel) filters which is the most efficient, but if you are not used to working with CAN will seem overly complicated at first. Then there is software level filtering which is simple but much slower.

    For simplicity it would be good to focus on the software filtering. Once you read a message from the CAN interface you can treat the message like many other python object. This is what is so beautiful about Brian's library. But because of this there is many different ways to deal with messages.

    Again not the most efficient way, but simple. **Did not check this for issues and assumes you have a two Bus objects initialized.

    recvMsg = canBus0.recv(timeout=None)
    if(recvMsg is not None and recvMsg == 0x100):
        respMsg = Message(extended_id=False, arbitration_id=0x101, data=[1,2,3,4,5,7,8])

    This should do the what you want in the most basic way. If you are dealing with many more messages and nodes on the CAN bus you will need a more custom approach and kernel level filtering.

    If you are having more trouble, try to ask a little a little more specific of a questions.

    Hope this help!

  2. Log in to comment