TTC控制器有专门支撑其can通信的库文件,其can数据的收发通过调用库文件所包含的can接收和can发送函数来实现,具体如下:
附上一段源代码:
IF bInit THEN
toucan_uti_setup_msg_buffer(
E_TOUCAN_B,
E_TOUCAN_MSG_BUF_1,
E_MSG_BUF_FUNCTION_READ,
16#184,
STANDARD_CAN_ID_FORMAT,
8);
toucan_uti_setup_msg_buffer(
E_TOUCAN_B,
E_TOUCAN_MSG_BUF_2,
E_MSG_BUF_FUNCTION_WRITE,
16#186,
STANDARD_CAN_ID_FORMAT,
8);
bInit := FALSE;
END_IF
(*
Depending on the 'change_can' variable send either one or the other of the specified CAN messages
wr_trigger = 1 starts writing the message provided in the byte array
While 'wr_status' is 0 the buffer has not yet been processed
*)
IF (NOT((changeCan))) THEN
toucan_write_msg(
E_TOUCAN_B,
E_TOUCAN_MSG_BUF_2,
16#186,
STANDARD_CAN_ID_FORMAT,
ADR(byte_array2),
SIZEOF(byte_array2),
wr_trigger,
ADR(wr_status));
ELSE
toucan_write_msg(
E_TOUCAN_B,
E_TOUCAN_MSG_BUF_2,
16#123,
STANDARD_CAN_ID_FORMAT,
ADR(byte_array2),
SIZEOF(byte_array2),
wr_trigger,
ADR(wr_status));
END_IF
2024-10-27
2024-10-02
本站致力于为国内中小型公司或个人提供基于CodeSys编程平台的项目承接和项目渠道,并为CodeSys相关从业专业人士提供知识与项目交流平台。