Failed to filter message

The free CAN Software API (Application Programming Interface) for Windows®
Locked
Embers
Posts: 12
Joined: Wed 8. Jul 2020, 11:36

Failed to filter message

Post by Embers » Thu 13. Aug 2020, 09:09

Hello,everyone
I want to filter some message that no need to receive,so I used PCANBasic.FilterMessages() function,however I still can read other message that i don't want to receive,there is my code.

Code: Select all

UInt32 iBuffer = PCANBasic.PCAN_FILTER_CLOSE;
                    stsResult = PCANBasic.SetValue(PCANBasic.PCAN_USBBUS1, TPCANParameter.PCAN_MESSAGE_FILTER, ref iBuffer, sizeof(UInt32));
                    if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                    {
                         PCANBasic.FilterMessages(m_PcanHandle, 0x18DAF13A, 0x18DAF13A, TPCANMode.PCAN_MODE_EXTENDED);
                         PCANBasic.FilterMessages(m_PcanHandle, 0x18FF003A, 0x18FF003A, TPCANMode.PCAN_MODE_EXTENDED);
                         //PCANBasic.FilterMessages(m_PcanHandle, 0x18FF1019, 0x18FF1019, TPCANMode.PCAN_MODE_EXTENDED);
                         PCANBasic.FilterMessages(m_PcanHandle, 0x18DA3AF1, 0x18DA3AF1, TPCANMode.PCAN_MODE_EXTENDED);
                    }
As shown in the code,I only want to read CANID 0x18DAF13A,0x18FF003A,0x18DA3AF1,0x18DA3AF1,but 0x18FF803A can still read it,as shown in the URL image below.

2020-08-13.png
2020-08-13.png (41.42 KiB) Viewed 4704 times
Does anybody know how to solve it?
Any effective help will be greatly appreciated!

Best regards
Embers
Last edited by M.Gerber on Thu 13. Aug 2020, 09:22, edited 2 times in total.
Reason: Inserted previously linked image directly in this post (for instant reference)

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

Re: Failed to filter message

Post by M.Heidemann » Thu 13. Aug 2020, 12:43

Hello Embers,

This is a hardware related beheaviour, it's also noted in the PCANBasic documentation (FilterMessages):
PCANBasic_FilterMessages.PNG
PCANBasic_FilterMessages.PNG (13.65 KiB) Viewed 4689 times
The way that the SJA1000 acceptance filter works can lead to situations like this, in your case my recommendation is to keep the hardware-filter and to implement your own filtering using an if-clause to discard unwanted messages.


Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Embers
Posts: 12
Joined: Wed 8. Jul 2020, 11:36

Re: Failed to filter message

Post by Embers » Thu 13. Aug 2020, 13:26

Hello Marvin
Thank you for your quick reply , you're right,but I read all message from CAN BUS maybe take a long time, because it read other message that not need from the FIFO,So if my own filter fuction ,it will also take a long time to filter and read the message that i needed, In my project i only want to read message that needed quickly.

Best Regares
Embers

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Failed to filter message

Post by K.Wagner » Thu 13. Aug 2020, 14:21

Hello,

as Marvin already said, this is due to the way how the CAN controller sets the filter. It cannot be guaranteed that you exactly receive the messages you entered. The filter is set using a 32 bit acceptance mask and 32 bit acceptance code. The bits that stay as "don't care" can take any form, so you will have more results as desired. This is a fact. For more information consult the data sheed of the SJA1000 CAN controller.

The proposal from Marvin is also right.
M.Heidemann wrote:
Thu 13. Aug 2020, 12:43
my recommendation is to keep the hardware-filter and to implement your own filtering using an if-clause to discard unwanted messages.
In this way the amount of messages the hardware accepts is limited as possible, and the rest can be filter out direct in the code.
Embers wrote:
Thu 13. Aug 2020, 13:26
if my own filter fuction ,it will also take a long time to filter and read the message that i needed
Don't think so. It shouldn't be a problem to read from the API and just discard the messages you don't need.
Best regards,
Keneth

Embers
Posts: 12
Joined: Wed 8. Jul 2020, 11:36

Re: Failed to filter message

Post by Embers » Fri 14. Aug 2020, 04:14

Hello Keneth
Thank you very much,that's clear to me,I will try to use sofeware filter the message.
Best Regards
Embers

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Failed to filter message

Post by K.Wagner » Fri 14. Aug 2020, 08:21

Hello,

ok. Just to sum up: In order to get the best accuracy on filtering you need to do two things:
  1. Limit the hardware filter as good as possible, using FilterMessages or SetValue(PCAN_ACCEPTANCE_FILTER_XX). This decreases the amount of messages received by the the hardware.
  2. Use additional software filter to discard messages you don't need, that are still going through the hardware filter.
Closed.
Best regards,
Keneth

Locked