can_bind()
Description
Binds a script to a CAN interface that is already configured and running under a CAN profile, giving the script read access to bus traffic without taking over or modifying the bus configuration (bit rate, mode, or filters).
Unlike can_init / can_fd_init, can_bind does not configure the interface – the CAN profile has already initialized it – so it can be called directly, without a prior can_init / can_fd_init call on the same interface.
Syntax
can_bind(can_interface, can_rx_buffer);
Parameters
Parameter | Description |
| CAN interface to initialize – CAN1 or CAN2. |
| Array reserved by the script to hold incoming raw CAN frame data; sized to the maximum amount of buffering required (can_rx_buffer{4096} in the example). |
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | The operation completed successfully. |
SCRIPT_OPERATION_FAILED | The operation could not be completed (invalid state, hardware error, etc.). |
SCRIPT_NO_ACCESS | The CAN interface has not been initialized. |
SCRIPT_PARAM_INVALID | One or more passed parameters are invalid. |
Function call example
#include <io>
#include <read>
#include <float>
#include <string>
#include <core>
#include <write>
#include <define>
#include <socket>
#include <can>
#define CAN_BUS CAN1
new can_rx_buffer{4096};
main()
{
can_bind(CAN_BUS, can_rx_buffer);
for(;;)
{
Delay(1000);
}
}Notes and Warnings
Use can_bind when a CAN profile owns the bus configuration and the script only needs to observe traffic; use can_init or can_fd_init instead when the script itself must own and configure the bus.
Because the bus configuration is not touched, functions that change it (can_nominal_bit_rate_set, can_fd_data_bit_rate_set, can_filter_reset, can_filter_mask_insert, can_filter_id_insert) are not meaningful on an interface accessed through can_bind.