WriteCANmsg()

WriteCANmsg()

Description

Writes message into CAN from source buffer.

Syntax

WriteCANmsg(id, source[]);

Parameters

Variable

Input

Variable

Input

id

CAN1 - Read from CAN1.

CAN2 - Read from CAN2.

source[]*

Source buffer/array from which data is going to be sent.

*each source[] buffer data cell of CAN frame will be cast to 1 byte. source[3 to n] will correspond with CAN frame data bytes 0 to n. Refer to source[] buffer structure in following example. Additional code is needed to serialize script cell content to CAN frame data bytes.

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

WriteCANmsg example
#define CAN1_MODE_READ #include <can> new can_tx_buffer[11] = [0x7CE, STANDARD, 8, 0x21, 0x32, 0x64, 0xAA, 0xBB, 0x11, 0x22, 0x33]; main() { Delay(5000); // Delay 5 sec. Init(CAN1, NORMAL, 500000, CAN1_READ); // Initialize CAN2, normal mode, speed: 500kbit/s WriteCANmsg(CAN1, can_tx_buffer); // Send CAN message with can_tx_buffer data for(;;) { Delay(1000); } }

Notes and Warnings

In case callback was used - always use ReadCANmsg(); function

Used in Examples

CAN example