canAccept

Syntax


#include <canlib.h>
canStatus canAccept(int handle, long envelope, int flag);

Description

This routine sets the message acceptance filters on a CAN channel.

Parameters

handle
An open handle to a CAN circuit.
envelope
The mask or code to set.
flag
Any one of the following values:
ValueMeaning
canFILTER_SET_CODE_STDSets the code for standard (11-bit) identifiers.
canFILTER_SET_MASK_STDSets the mask for standard (11-bit) identifiers.
canFILTER_SET_CODE_EXTSets the code for extended (29-bit) identifiers.
canFILTER_SET_MASK_EXTSets the mask for extended (29-bit) identifiers.
Return Value

canOK (zero) if success
canERR_xxx (negative) if failure.

Code and Mask format

A binary 1 in a mask means "the corresponding bit in the code is relevant"

A binary 0 in a mask means "the corresponding bit in the code is not relevant"

A relevant binary 1 in a code means "the corresponding bit in the identifier must be 1"

A relevant binary 0 in a code means "the corresponding bit in the identifier must be 0"

In other words, the message is accepted if ((code XOR id) AND mask) == 0.

Notes
  • You can set the extended code and mask only on CAN boards that support extended identifiers.
  • Not all CAN boards support different masks for standard and extended CAN identifiers.
  • If you want to remove a filter, call canAccept with the mask set to 0.
  • On some boards the acceptance filtering is done by the CAN hardware; on other boards (typically those with an embedded CPU,) the acceptance filtering is done by software. canAccept behaves in the same way for all boards, however.
  • canSetAcceptanceFilter and canAccept both serve the same purpose but the former can set the code and mask in just one call.