Filter for only specific IDs in PCAN Basic API

This forum covers issues concerning multiple software products.
Post Reply
PROATE
Posts: 2
Joined: Thu 2. Dec 2021, 08:04

Filter for only specific IDs in PCAN Basic API

Post by PROATE » Thu 2. Dec 2021, 08:10

Good morning,

I would like to have a filter for only certain CAN IDs instead of using an "allowed" range. We have a CAN device from a different vendor that allows for simply adding and removing CAN Ids from the filter, without having to provide a full range.

Is this somehow possible with the PCAN Basic API? I checked the documentation, but it looks like PCAN_MESSAGE_FILTER doesnt allow for that.

Thank you in advance,

BR

M.Heidemann
Sales & Support
Sales & Support
Posts: 754
Joined: Fri 20. Sep 2019, 13:31

Re: Filter for only specific IDs in PCAN Basic API

Post by M.Heidemann » Thu 2. Dec 2021, 12:16

Hello,

You can push individual IDs to the hardware-filter by only giving
the same ID when calling "FilterMessages":

Code: Select all

## Set cascading filters:
        stsResult = self.m_objPCANBasic.FilterMessages(self.PcanHandle, 0x102, 0x102,  PCAN_MESSAGE_STANDARD)
        if stsResult != PCAN_ERROR_OK and stsResult != PCAN_ERROR_QRCVEMPTY:
            self.ShowStatus(stsResult)

        stsResult = self.m_objPCANBasic.FilterMessages(self.PcanHandle, 0x108, 0x108,  PCAN_MESSAGE_STANDARD)
        if stsResult != PCAN_ERROR_OK and stsResult != PCAN_ERROR_QRCVEMPTY:
            self.ShowStatus(stsResult)
            
        stsResult = self.m_objPCANBasic.FilterMessages(self.PcanHandle, 0x131, 0x131,  PCAN_MESSAGE_STANDARD)
        if stsResult != PCAN_ERROR_OK and stsResult != PCAN_ERROR_QRCVEMPTY:
            self.ShowStatus(stsResult)

Beware: The SJA1000-hardware filter has its quirks.
Sometimes messages still make it through (depending on the underlying bitmask, for more info see PCANBasic docs)
You cannot mix Standard and Extended IDs as it makes this more likely to happen.

Alternatively you can also use a software-filter (using if-conditions) or use a combination of the hardware-filter and a software-implementation to catch any unexpcted id coming through.

For further questions feel free to contact us again.

Best Regards

Marvin

PROATE
Posts: 2
Joined: Thu 2. Dec 2021, 08:04

Re: Filter for only specific IDs in PCAN Basic API

Post by PROATE » Fri 3. Dec 2021, 09:59

Thank you very much, that is exactly what I needed.

Post Reply