How can I filter only two messages?

USB to CAN Interface
JOHNPILOK
Posts: 6
Joined: Wed 14. Sep 2022, 16:59

How can I filter only two messages?

Post by JOHNPILOK » Wed 14. Sep 2022, 17:49

Hi friends

I am a developer and I develop apps with visual studio ( C#) , I have purchased a USB to CAN interface and use the samples of develop (C#) to develop my app now , but I have a problem when read all messages from CAN BUS .

in the first stage I connect USB to CAN interface to the car, then in the sample of develop (C#) click on Initialize button and receive messages continuous from the car. but I don't want all messages from the car, in order to prevent this action, I filter car messages via FilterMessages function in PCANBasic class , but I have a problem at this stage as well,because FilterMessages function filters messages from specified range to specified range , while I want to recieve only two messages from the car and I want to filter only this two message via FilterMessage,is there a way that I can filter only two messages?
please guide me in this regard

"I would like to make on point that when receive all messages from the car , I'll receive this two messages with delay that often missed , but when I filter one of messages,I receive same message immediate"

thanks in advance

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

Re: How can I filter only two messages?

Post by K.Wagner » Thu 15. Sep 2022, 07:53

Hello,

for filtering messages you have two possibilities:
  • Using the method PCANBasic.FilterMessages
  • Using the method PCANBasic.SetValue with the parameter TPCANParameter.PCAN_ACCEPTANCE_FILTER_11BIT / TPCANParameter.PCAN_ACCEPTANCE_FILTER_29BIT
JOHNPILOK wrote:
Wed 14. Sep 2022, 17:49
but I have a problem at this stage as well,because FilterMessages function filters messages from specified range to specified range
Yes, this is true. But using the same ID for both values of the range is also valid. So, for example, to only filter for the ID 0x100, you can call the method like this "PCANBasic.FilterMessages(channel,0x100,0x100, TPCANMode.PCAN_MODE_STANDARD)". Calling this again with a different ID will augment the filter.

The acceptance filter is used as a pattern to restringe incoming messages. More information about this in the docuemtnation of those parameters in the PCAN-Parameter documentaiton pdf and the CHM help file.
JOHNPILOK wrote:
Wed 14. Sep 2022, 17:49
"I would like to make on point that when receive all messages from the car , I'll receive this two messages with delay that often missed , but when I filter one of messages,I receive same message immediate"
Please note that messages are received same not depending in how you read them. Messages are placed in the reception queue of the driver and are dequeued when using the method PCANBasic.Read/ReadFD. Please check the way you are reading messages.

Note on filtering: Note that in some cases you can still get unwanted messages, even if you have defined a filter. This is per design like this. More information can be found in the Philips Data Sheet SJA1000 Stand-alone CAN-controller.
Best regards,
Keneth

JOHNPILOK
Posts: 6
Joined: Wed 14. Sep 2022, 16:59

Re: How can I filter only two messages?

Post by JOHNPILOK » Thu 15. Sep 2022, 11:28

thanks for your answer
For example, I want to filter only 0x100 and 0x702, when I filter these two messages with "FilterMessages" method, all messages between 0x100 and 0x702 are received while I want only "0x100" and " 0x702" are displayed.
How can I filter these two messages?

Is it possible to filter these two messages through the "FilterMessages" method?

Please explain me how to filter the above two messages.

thanks in advance

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

Re: How can I filter only two messages?

Post by K.Wagner » Thu 15. Sep 2022, 12:15

Hello,

I already gave you this information in my last post... did you miss it?
K.Wagner wrote:
Thu 15. Sep 2022, 07:53
So, for example, to only filter for the ID 0x100, you can call the method like this "PCANBasic.FilterMessages(channel,0x100,0x100, TPCANMode.PCAN_MODE_STANDARD)". Calling this again with a different ID will augment the filter.
Best regards,
Keneth

JOHNPILOK
Posts: 6
Joined: Wed 14. Sep 2022, 16:59

Re: How can I filter only two messages?

Post by JOHNPILOK » Thu 15. Sep 2022, 14:00

To do this you mean the following steps:

1- In the first step, I use the Filter Messages method as follows
PCANBasic.FilterMessages(channel,0x100,0x100, TPCANMode.PCAN_MODE_STANDARD)

2- Then for the second message which is "0x702", I have to repeat the same command as above but instead of "0x100" set the value of "0x702" in the following syntax.

PCANBasic.FilterMessages(channel,0x702,0x702, TPCANMode.PCAN_MODE_STANDARD)

Is the above description the same as your description?
next my question is:
will filtering two messages consecutively via the method "FilterMessage", filter both messages ?

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

Re: How can I filter only two messages?

Post by K.Wagner » Thu 15. Sep 2022, 14:31

JOHNPILOK wrote:
Thu 15. Sep 2022, 14:00
Is the above description the same as your description?
yes.
JOHNPILOK wrote:
Thu 15. Sep 2022, 14:00
will filtering two messages consecutively via the method "FilterMessage", filter both messages ?
yes. As I wrote ( and as seen in the documentaiton of the function), the filter is augmented in the new range wihtin further calls. In the following picutre, the number 1 corresponds to the sate of the filter by the first call, the number 2 for the state on the second call.
Documentation of the method PCANBasic.FilterMessages
Documentation of the method PCANBasic.FilterMessages
PCANBasic.PNG (39.74 KiB) Viewed 6474 times
Best regards,
Keneth

JOHNPILOK
Posts: 6
Joined: Wed 14. Sep 2022, 16:59

Re: How can I filter only two messages?

Post by JOHNPILOK » Thu 15. Sep 2022, 16:33

thanks for your answer

I filtered both messages (100 and 702) as you instructed
Are the commands below correct???

Do I just read and receive both above messages with the commands below?
If it is need to modify the commands below, please let me know

Code: Select all

  UInt32 iBuffer;
  TPCANStatus stsResult;
  stsResult = PCANBasic.FilterMessages(m_PcanHandle,100 ,100,TPCANMode.PCAN_MODE_STANDARD);
  stsResult = PCANBasic.FilterMessages(m_PcanHandle,702 ,702,TPCANMode.PCAN_MODE_STANDARD);
  iBuffer = PCANBasic.PCAN_FILTER_OPEN;
  stsResult = PCANBasic.SetValue(m_PcanHandle,TPCANParameter.PCAN_MESSAGE_FILTER,ref iBuffer, sizeof(UInt32));

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

Re: How can I filter only two messages?

Post by K.Wagner » Fri 16. Sep 2022, 08:43

Hello,

Still a thrid try to explain the same thing: You just need to call PCANBasic.FilterMessages twice, one for each ID you need. Then you can start reading messages and you should get only the wanted ones (and possibly a couple of unwanted messages too due to the SJA1000 filtering as mentioned in other post).

REMARK 1: I never said something about calling PCANBasic.SetValue(...TPCANParameter.PCAN_MESSAGE_FILTER...). This makes no sense. calling this after configuring the custom filter just open the filter again for "ALL" IDs.
CAN-Filter.PNG
CAN-Filter.PNG (26.25 KiB) Viewed 6464 times
REMARK 2: Pay attention to what you are configuring. You first posted that you need the IDs 0x100 and 0x702 (hexadecimal values). In your last post you are configuring decimal values, 100 and 702.

REMARK 3: Please, read the documentation, check the sample projects, and try to understand how the API works. It makes no sense to just make try and error with this, if you do not understand it. You have several sample applications in several programming languages within the PCAN-Basic package that even allow doing what you are trying to do.
Sample.PNG
Sample.PNG (16.59 KiB) Viewed 6464 times
.

I gave you the same information already three times. There will be no fourth one. Thanks for your understanding.
Best regards,
Keneth

JOHNPILOK
Posts: 6
Joined: Wed 14. Sep 2022, 16:59

Re: How can I filter only two messages?

Post by JOHNPILOK » Fri 16. Sep 2022, 10:19

Hi dear friend

thanks for your answer
By the way, I am not dumb

But my dear friend, I want code in this field, not explanations

I gave you a code and told you whether this code is correct or not

But you gave the same explanation as before and I was again confused

If it is possible, please give me some code that will filter both 0x100 and 0x702 messages

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: How can I filter only two messages?

Post by PEAK-Support » Fri 16. Sep 2022, 16:56

Sorry - but this comment is a no go !
By the way, I am not dumb
Nobody called you dumb - but my colleauge explain now 3 times how to set a 11Bit ID Filtering , and also forward to the Online Help and also to the available Source Code and the ready to use sample. (which you simply could try and so understand it if you do not understand the Online Help)

So here again:

Device is initialized, no filter is set - all frames will be received and are part of the incomming queue now - then:

1. Close the Filter complete

Code: Select all

iBuffer = PCANBasic.PCAN_FILTER_CLOSE;
result = PCANBasic.SetValue(PCANBasic.PCAN_USBBUS1, TPCANParameter.PCAN_MESSAGE_FILTER, ref iBuffer, sizeof(UInt32));
2. Open from ID 0x100 to 0x100

Code: Select all

 // The message filter is configured to receive the IDs 0x100 on the PCAN-USB, Channel 1
 result = PCANBasic::FilterMessages(PCANBasic::PCAN_USBBUS1, 0x100, 0x100, TPCANMode::PCAN_MODE_STANDARD);
3. Open from ID 0x702 to 0x702

Code: Select all

 // The message filter is configured to receive the IDs 0x702 on the PCAN-USB, Channel 1
result = PCANBasic::FilterMessages(PCANBasic::PCAN_USBBUS1, 0x702, 0x701, TPCANMode::PCAN_MODE_STANDARD);
from now on only ID0x100 and 0x702 (both Std ID´s) will be received. If you need more Filter , repeat until you have all you need. You could close it again to restart the Setup of the filtering.

In the Online Help are samples which explain it very well... Always keep in mind only 11Bit ID´s could be filtered 1:1 - Ext. IDs could not - see SJA1000 Data Sheet (A-Mask / A-Code Register)
Attachments
PCAN-Basic_Filter_Info.JPG
PCAN-Basic_Filter_Info.JPG (149.02 KiB) Viewed 6453 times
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Locked