can_status_get()
Description
Reads the current run-time status of a CAN interface into a can_status structure (controller state, error counters, active bit rates, and frame count).
Syntax
can_status_get(can_interface, can_status);
Parameters
Parameter | Array structure | Description |
|
| CAN interface to query – CAN1 or CAN2. |
|
| Current controller state:
|
| Bitwise error code flags, or 0 when no error is pending:
| |
| CAN controller transmit error counter. | |
| CAN controller receive error counter. | |
| Number of frames processed since the interface was initialized. | |
| Nominal (arbitration phase) bit rate currently configured, in bit/s. | |
| FD data-phase bit rate currently configured, in bit/s (0 when FD/BRS is not enabled). | |
| Last CAN bus status change reason:
|
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 (call can_fd_init first). |
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_status[.state, .error, .tx_error_count, .rx_error_count, .frame_count, .bit_rate, .data_bit_rate, .status_flags];
new can_rx_buffer{4096};
main()
{
can_fd_init(CAN_BUS, CAN_CTRL_MODE_NORMAL | CAN_CTRL_MODE_ONE_SHOT | CAN_CTRL_MODE_FD_BRS, 2000, 500000, can_rx_buffer);
for(;;)
{
can_status_get(CAN_BUS, can_status);
Delay(1000);
}
}