Page 1 of 1

Failed to filter message

Posted: Thu 13. Aug 2020, 09:09
by Embers
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 4705 times
Does anybody know how to solve it?
Any effective help will be greatly appreciated!

Best regards
Embers

Re: Failed to filter message

Posted: Thu 13. Aug 2020, 12:43
by M.Heidemann
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 4690 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

Re: Failed to filter message

Posted: Thu 13. Aug 2020, 13:26
by Embers
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

Re: Failed to filter message

Posted: Thu 13. Aug 2020, 14:21
by K.Wagner
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.

Re: Failed to filter message

Posted: Fri 14. Aug 2020, 04:14
by Embers
Hello Keneth
Thank you very much,that's clear to me,I will try to use sofeware filter the message.
Best Regards
Embers

Re: Failed to filter message

Posted: Fri 14. Aug 2020, 08:21
by K.Wagner
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.