CANconfig(...,mask_type,...)
Description
Configures CAN BUS interface for reading. Adds CAN mask filter.
Syntax
CANconfig(id, mask_type, result, mask);
Parameters
Variable | Input |
|---|---|
| CAN1 - Reset filters of CAN1. CAN2 - Reset filters of CAN2. |
| ADD_MASK_STD - Add standard 11-bit CAN mask. ADD_MASK_EXT - Add extended 29-bit CAN mask. |
| Expected result after mask. |
| User defined mask in hex (for example 0x7C6). |
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | Success |
SCRIPT_OPERATION_FAILED | Failed |
SCRIPT_NO_ACCESS | CAN not initialized. |
SCRIPT_PARAM_INVALID | Passed parameters invalid. |
Function call example
CANconfig example
#define CAN1_MODE_READ
#include <can> // Include can library
new can_rx_buffer[11];
forward public callback (event);
public callback (event)
{
switch(event)
{
case CAN1: // CAN1 callback event
{
ReadCANmsg(CAN1, CANRxBuffer);
}
}
return 0;
}
main()
{
Init(CAN1, NORMAL, 500000, CAN1_READ);
CANconfig(CAN1,RESET_FILTER); // Reset all filters before setting new
CANconfig(CAN1, ADD_MASK_EXT, 0x00FEE900, 0x00FFFF00);
//CANconfig(CAN1, ADD_MASK_EXT, 0x00000000, 0x00000000); - Receive all messages
for(;;)
{
Delay(100);
}
}Notes and Warnings
Filter limitations:
on XG37 series devices:
28 Extended Mask filters for both CANs in total;
56 Extended ID filters for both CANs in total;
56 Standard Mask filters for both CANs in total;
112 Standard ID filters for both CANs in total.
Filters are shared with canbase_b - using CAN Vehicle Model will reduce free filters available for scripts.
Before using filter config, first it is recommended to use command RESET_FILTER, to clear all previously set filters.