PCANBasic filtermessage question (python)

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
esun95070
Posts: 4
Joined: Tue 5. May 2015, 22:25

PCANBasic filtermessage question (python)

Post by esun95070 » Mon 23. Nov 2015, 20:08

I still receive all messages with odd message id (such as 0x1b7, 0x1b9) but not even id (0x1b6) in the test code below.

Please advise, thank you.

Code: Select all

self.m_objPCANBasic.SetValue (PCAN_USBBUS,  PCANBasic.PCAN_MESSAGE_FILTER,  PCANBasic.PCAN_FILTER_CLOSE)
self.m_objPCANBasic.FilterMessages(PCAN_USBBUS,  0,  1, PCANBasic.PCAN_MESSAGE_STANDARD )
self.m_objPCANBasic.FilterMessages(PCAN_USBBUS,  0,  1, PCANBasic.PCAN_MESSAGE_EXTENDED )
Last edited by M.Gerber on Tue 24. Nov 2015, 11:43, edited 1 time in total.
Reason: Inserted [code] tag for better readability.

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

Re: PCANBasic filtermessage question (python)

Post by K.Wagner » Tue 24. Nov 2015, 09:32

Hello,
  1. the handle you are using is wrong. It lacks the channel number. Try using PCAN_USBBUS1, for example.
  2. check the return value of each function call to know if it was successfully executed.
  3. filtering is done as described in the SJA1000 document (see 6.4.15, acceptance filter). There is only one filter for standard and extended IDs, so there is not warranty to get only those IDS you are expecting. Adjusting the filter for get messages with ID 0 to 1 standard, AND IDs 0 to 1 extended will probably permit more than those IDs to be received.
Best regards,
Keneth

esun95070
Posts: 4
Joined: Tue 5. May 2015, 22:25

Re: PCANBasic filtermessage question (python)

Post by esun95070 » Wed 25. Nov 2015, 01:47

Keith,

Thanks for the info.

PCAN_USBBUS is the actual channel number, not a good naming convention on my part!

Thank you for the info on filter, yes, bit patterns of both 11 and 29 have to be set for the filter and, due to the overlapping bits, certain message IDs will go through as a result.

Again, your help is appreciated.

Eric

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

Re: PCANBasic filtermessage question (python)

Post by K.Wagner » Wed 25. Nov 2015, 09:01

OK,

please note that the function FilterMessages uses CAN IDs to filter (not bit patterns, aka mask and code). That is, passing the values 0 and 1 as in your code would mean that you want to receive only CAN messages with ID 0x0 and ID 0x1. If you want to receive the ID 0x1b6 you should use the following code:

Code: Select all

self.m_objPCANBasic.FilterMessages(PCAN_USBBUS,  0x1b6 ,  0x1b6 , PCANBasic.PCAN_MESSAGE_STANDARD )
PCAN-Basic calculates internally filter acceptance mask and acceptance code patterns using the range of IDs passed to the FilterMessage function.

Note that each time you call FilterMessages the filter will be expanded. So, if you want to reconfigure your filter, then you need to close it first, so that it can be reset.
Best regards,
Keneth

Post Reply