How to filter frames with CANBus API ?

paulpotat
2022-06-01
2022-06-03
  • paulpotat

    paulpotat - 2022-06-01

    Hello everyone,

    I'm trying to use the CANBus API I found in the CodeSys Store (documentation here) but I can't figure out how the filtering process works.

    I have a CAN bus with 2 devices and I want to only receive the messages containing a specific ID (10614061). I thought it was possible using the receiver mask object of the CANBus API but I don't understand what I'm supposed to write in the parameters values...

    FYI I'm running the base example given in the CANBus API and I only tried modifying the mask configuration like this :

    (* Defines a mask for the receiver *)
    maskConfig      : CAN.RECEIVER_MASK := (
                                        dwIdValue:= 10614061,
                                        dwIdMask:= 0,
                                        xRTRValue:= FALSE, 
                                        xRTRMask:= FALSE,
                                        x29BitIdValue := FALSE,
                                        x29BitIdMask := FALSE,
                                        xTransmitValue:= FALSE, 
                                        xTransmitMask:= FALSE,
                                        xAlwaysNewest:=FALSE);
    

    However I'm still receiving all the messages going through the CAN bus, it doesn't filter anything.

    What am I doing wrong ?

     
  • TimvH

    TimvH - 2022-06-03

    As you have a long ID, you should set the x29BitIdValue and Mask to TRUE.

    The mask works in a way that if you set the bit to 1, that it should exactly match the bit in the received message. If you set this to 0, then you don't care. So if you set the mask to 16#1FFFFFFF (29 bits bit true, so should exactly match the dwIdValue), then you should only see the message you want to see. For more information see: https://content.helpme-codesys.com/en/libs/CAA%20Can%20Low%20Level%20Extern/Current/CAN-Low-Level/Functions/Basic-Functions/CreateMaskReceiver.html

     
    πŸ‘
    1
    • paulpotat

      paulpotat - 2022-06-03

      Thank you for your answer, it works perfectly fine now !

      I think I also made a mistake by using a 11 bit driver while some of the IDs on the bus are 29 bits.
      However the 11 bit driver works with 29 bits ID somehow ? How is this possible ?

      Also I didn't know the website helpme-codesys.com, what's the difference with help.codesys.com ?

       

Log in to post a comment.