Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY
These functions set data of diverse non-safe SRDO variables and their timestamps according to given safe variable.
The timestamp output values are the last- time-to-send µs-values for firmware.
The plain and inverted messages are rejected (not sent) if the set time has passed.
Each supported variable type has a function.
Function |
Data type of S_i_Input |
Data type of o_PlainMsgData and o_InvertMsgData |
CreateSRDO_BYTE |
SAFEBYTE |
BYTE |
CreateSRDO_WORD |
SAFEWORD |
WORD |
CreateSRDO_DWORD |
SAFEDWORD |
DWORD |
CreateSRDO_SINT |
SAFESINT |
SINT |
CreateSRDO_INT |
SAFEINT |
INT |
CreateSRDO_DINT |
SAFEDINT |
DINT |
CreateSRDO_USINT |
SAFEUSINT |
USINT |
CreateSRDO_UINT |
SAFEUINT |
UINT |
CreateSRDO_UDINT |
SAFEUDINT |
UDINT |
If given S_i_TransmitTimeout delay time is 0, return value is set FALSE and data outputs are set to 0. The current time is set to the time outputs.
|
Value 0 in CAN message's timestamp causes no checking for last time to send. |
A safe application runs safe and non-safe tasks. Due lower priority, the non-safe task may be interrupted at any time by the safe task.
If an interrupt occurs while the application is handling diverse non-safe SRDO data, the validation will fail.
The non-safe CANopenSRDO protocol handler keeps the global lock status TRUE while handling transmit message data.
The global lock status shall be used to skip CreateSRDO function call when CANopen is copying data from OD.
|
SRDO protocol is supported in CANopen library version 4.0.0.0 or newer. |
|
These functions do not send anything to CAN bus. |
|
The output data variables must be copied to mapped OD variables. Both o_PlainMsgData and o_InvertMsgData. |
|
In addition, the SRDO must be set up properly. |
|
SRDO message's refresh time (tx interval) shall be greater than 2x safety task's cycle time for SRDO to work properly with interlock functionality. |
Input variable name |
Data type |
Range |
Description |
S_i_Input |
See table above. |
- |
Safe data to be sent over SRDO protocol. |
S_i_TransmitTimeout |
SAFEUINT |
> 0 |
Maximum elapsed time (ms) between data setting and sending to CAN bus. |
Output variable name |
Data type |
Range |
Description |
o_PlainMsgData |
See table above. |
- |
Data of mapped SRDO plain variable. |
o_InvertMsgData |
See table above. |
- |
Data of mapped SRDO inverted variable. |
o_PlainMsgTime |
UDINT |
- |
SRDO plain variable timestamp. |
o_InvertMsgTime |
UDINT |
- |
SRDO inverted variable timestamp. |
Data type |
Description |
BOOL |
TRUE = Given timeout parameter ok and system time returned ok. FALSE = Otherwise |
|
SRDO related POUs are automatically generated to code template when MultiTool Creator is used.
|
Definitions: |
|
(*NOTE! This code is created by Epec MultiTool Creator*)
/// SRDO variables /// Plain SRDO variables tdw1 AT %MD0: DWORD := DWORD#16#0; tdw2 AT %MD1: DWORD := DWORD#16#0; /// Inverted SRDO variables tdw1_i AT %MD2: DWORD := DWORD#16#0; tdw2_i AT %MD3: DWORD := DWORD#16#0; /// Plain SRDO variable timestamps tdw1_TIME: UDINT := UDINT#0; tdw2_TIME: UDINT := UDINT#0; /// Inverted SRDO variable timestamps tdw1_i_TIME: UDINT := UDINT#0; tdw2_i_TIME: UDINT := UDINT#0;
/// SRDO variable mappings SRDO1Mappings: ARRAY [1..G_CANOPEN_NUMBER_OF_LAST_SRDO_MAP*2] OF DWORD := [ DWORD#16#5FD60120, (* tdw1 *) DWORD#16#5FD50120, (* tdw1_i *) DWORD#16#5FD60220, (* tdw2 *) DWORD#16#5FD50220, (* tdw2_i *) 12(DWORD#16#0)]; (* 16 - 4 = 12 *)
/// CANopen common Device: EPEC_CANopen.Device; Protocols: ARRAY[1..6] OF EPEC_CANopen.ProtocolEntry; ProtocolAdded: ARRAY[1..6] OF BOOL := [6(0)];
/// SRDO SRDO: EPEC_CANopen.SRDOData; (* Protocol data *) SRDOS: ARRAY[1..2] OF EPEC_CANopen.CANopenSRDO; (* SRDO instances *) SRDO_Handler: EPEC_CANopen.CANopenSRDOHandler; (* Protocol handler *) SRDO_Error: EPEC_CANopen.Errors := EPEC_CANopen.Errors.NotInitialized; SRDO_Triggers: ARRAY[1..2] OF BOOL; SRDO_Signatures: ARRAY[1..2] OF WORD; SRDO_EventCodes: ARRAY[1..2] OF EPEC_DITF.EventCode; SRDO_Interlock: ARRAY[1..2] OF BOOL;
|
Initialization:
(*NOTE! This object is created by Epec MultiTool Creator*)
|
|
(*Define SRDO protocol*) Protocols[6].Protocol := EPEC_CANopen.ProtocolType.SRDO; Protocols[6].pData := ADR(SRDO); Protocols[6].itfProtocol := SRDO_Handler; Protocols[6].pError := ADR(SRDO_Error); ProtocolAdded[6] := CANopenDeviceAddProtocol( (* Add to protocol stack *) i_pDevice := ADR(Device), i_pProtocol := ADR(Protocols[6]) ); IF ProtocolAdded[6] THEN SRDO_Handler.Init( i_pDevice := ADR(Device) ); ELSE SRDO_Error := EPEC_CANopen.Errors.ProtocolDataMissing; END_IF
(* Init SRDOs *) SRDOS[1].i_pTimings[1]:= ADR(tdw1_TIME); (*tdw1 *) SRDOS[1].i_pTimings[2]:= ADR(tdw1_i_TIME); (*tdw1_i *) SRDOS[1].i_pTimings[3]:= ADR(tdw2_TIME); (*tdw2 *) SRDOS[1].i_pTimings[4]:= ADR(tdw2_i_TIME); (*tdw2_i *) SRDOS[1].Init( i_pDevice := ADR(G_CANopen_CAN1.Device), i_SRDONumber := 1, i_SRDOType := EPEC_CANopen.SRDOType.TransmitSRDO, i_SCTime := UINT#25, (* TSRDO Refresh Time (ms) *) i_SRVTime := USINT#0, (* Validation time (rx) (ms) *) i_COB_ID1 := DWORD#16#101, (* Plain message COB-ID *) i_COB_ID2 := DWORD#16#102, (* Inverted message COB-ID *) i_Mapping := SRDO1Mappings, (* Plain + Inverted data mappings *) i_Mappings := 4, (* Plain + Inverted data mappings *) i_pInterlock := ADR(SRDO_Interlock[1]), o_Error => SRDO_Error );
|
Code: |
|
(*NOTE! This object is created by Epec MultiTool Creator*)
// Update protocol data SRDO_Handler.Update( i_Enable := TRUE, (*Enable condition is set by MultiTool Creator code template*) o_Error => SRDO_Error ); |
|
|
Definitions: |
(*NOTE! This object is created by Epec MultiTool Creator*)
PROGRAM S_Create_SRDOs_CAN1
VAR_INPUT S_i_tdw1: SAFEDWORD := DWORD#16#0; S_i_tdw2: SAFEDWORD := DWORD#16#0; END_VAR
|
Code: |
(*NOTE! This object is created by Epec MultiTool Creator*)
IF NOT SRDO_Interlock[1] THEN // SRDO 1 data txSRDO_Ok := EPEC_SRDO.CreateSRDO_DWORD( S_i_Input := S_i_tdw1, S_i_TransmitTimeout := SRDOS[1].i_SCTime, o_PlainMsgData => tdw1, o_InvertMsgData => tdw1_i, o_PlainMsgTime => tdw1_TIME, o_InvertMsgTime => tdw1_i_TIME ); END_IF
IF NOT SRDO_Interlock[1] THEN txSRDO_Ok := txSRDO_Ok AND EPEC_SRDO.CreateSRDO_DWORD( S_i_Input := S_i_tdw2, S_i_TransmitTimeout := SRDOS[1].i_SCTime, o_PlainMsgData => tdw2, o_InvertMsgData => tdw2_i, o_PlainMsgTime => tdw2_TIME, o_InvertMsgTime => tdw2_i_TIME ); END_IF |