Page 1 of 1

PCANBasic filtermessage question (python)

Posted: Mon 23. Nov 2015, 20:08
by esun95070
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 )

Re: PCANBasic filtermessage question (python)

Posted: Tue 24. Nov 2015, 09:32
by K.Wagner
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.

Re: PCANBasic filtermessage question (python)

Posted: Wed 25. Nov 2015, 01:47
by esun95070
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

Re: PCANBasic filtermessage question (python)

Posted: Wed 25. Nov 2015, 09:01
by K.Wagner
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.