Supported platforms: CODESYS 3.5 SAFETY

 

CanApiTimeTriggeredMsg (FB)

Description

This function block (FB) is used to define time triggered CAN message. The maximum number of messages is 10.

Minimum time interval for sending is 1 ms, but it is recommended to use intervals > 10 ms.

Message is initialized with InitCobId method and sending is started by setting i_Enable to TRUE.

Function block must be called at least every 100 ms, otherwise sending is stopped. New data is updated

by setting new values to i_Dlc and i_Data inputs and calling UpdateData method.

 

Limitations

  • Maximum number of the send messages is 10

  • Accuracy of the time is +-2 ms

  • Minimum time interval for sending is 1 ms, but it is recommended to use intervals > 10 ms.

  • Used CAN channel must be initialized before initializing the time triggered messages.

  • Function block instance must be called at least every 100 ms, otherwise message sending is stopped

 

 

InitCobId (METHOD)

This method initializes time triggered CAN message.

 

Inputs

Input variable name

Data type

Description

i_CanChannel

BYTE

Used CAN channel

i_CobId

DWORD

Used COB-ID

i_TimeInterval

TIME

Time interval for sending

Return value

Data type

Description

EPEC_SYSTEM.SYSTEM_ERROR_CODES

FW error code.

 

RemoveCobId (METHOD)

This method removes time triggered CAN message.

The method has no inputs.

Return value

Data type

Description

EPEC_SYSTEM.SYSTEM_ERROR_CODES

FW error code.

 

UpdateData (METHOD)

This method updates i_Dlc and i_Data values of time triggered CAN message.

The method has no inputs.

Return value

Data type

Description

EPEC_SYSTEM.SYSTEM_ERROR_CODES

FW error code.

 

Normal operation

Inputs

Input variable name

Data type

Description

i_Enable

BOOL

Enable operation

i_Dlc

BYTE

Message length

i_Data

ARRAY [0..7] OF BYTE

Message data

Outputs

Output variable name

Data type

Description

o_UsedCanChannel

BYTE

Configured channel (= input for method InitCobId).

o_InitializedCobId

DWORD

Configured COB-ID (= input for method InitCobId).

o_UsedTimeInterval

TIME

Configured time interval (= input for method InitCobId).

o_Error

EPEC_SYSTEM.SYSTEM_ERROR_CODES

FW error code.

 

Example code

Definitions:

 

canChannel:EPEC_CANL2.Channel; (*not required with MT code template*)

timeTrgSending:EPEC_HWD.CanApiTimeTriggeredMsg;

 

Init:

 

(*If using MultiTool Creator, CAN channel init is already included in code template*)

canChannel.InitCAN(0,250,0);                    (* Init channel 0 for 250 kbit/s*)

 

timeTrgSending.i_Enable := FALSE;

timeTrgSending.i_Dlc := 8;

timeTrgSending.InitCobId(0,16#100,T#10MS);      (* Init message, 10ms interval *)

 

 

 

Code:

 

(*Update message data*)

timeTrgSending.i_Data[0] : = 1;

timeTrgSending.i_Data[1] : = 2;

timeTrgSending.i_Data[2] : = 3;

timeTrgSending.i_Data[3] : = 4;

timeTrgSending.i_Data[4] : = 5;

timeTrgSending.i_Data[5] : = 6;

timeTrgSending.i_Data[6] : = 7;

timeTrgSending.i_Data[7] : = 8;

(*Update data for message handler*)

timeTrgSending.UpdateData();

(*Call handler periodically*)

timeTrgSending(i_Enable := TRUE);    

 

 

See also

 

 

Source file topic100471.htm

Last updated 13-Jun-2024