Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY
This function block is used to validate compatibility between control unit code templates and parameter csv on HMI unit.
This is done by comparing 16-bit CRC on control unit's code template (OD index 2131h sub 0), which is generated by MultiTool Creator, and CRC calculated by function block (see Init method).
FB instance checks all nodes which are found from csv file (i.e. has at least one parameter).
Init method needs to be executed once before the main block. Otherwise o_State value is InitError.
When i_Enable is set to TRUE and initialization is OK then validation sequence is started:
o_State is set to Processing
Each node-id’s state is initialized to Idle
CANopen CSDO is used to read OD index 2131h sub 0 from each node-id which was found from parameter csv during initialization
If OD value matches with CRC generated in Init, then node’s state is NodeOK
If index was read successfully but value does not match, then state is Mismatch
Otherwise state depends on encountered error (see UniqueIDState enumeration)
Handler’s o_State value after the sequence depends on node states.
AllNodesOK if value matches on all nodes
AllNodesMismatch if value was successfully read from all nodes but none of the values match (possibly wrong csv or SW)
Mismatch if at least one Mismatch node-state is active
Error state if CSDO errors were encountered
State and sequence is reset if i_Enable is set false.
GetNodeState method can be used to read each node-id’s state individually.
Requires control unit code template which has OD index 2131h defined and value calculated by MultiTool Creator. |
Input variable name |
Data type |
Range |
Description |
i_Enable |
BOOL |
|
Sequence is started when TRUE |
Output variable name |
Data type |
Range |
Description |
o_State |
UniqueIDState |
see enumeration |
Returns Processing when checking is in progress, AllNodesOK if all nodes values match, Mismatch if one of the nodes value does not match, AllNodesMismatch if none of the nodes value matches (wrong csv) |
Init method needs to be executed once by application. CRC is calculated for each node-id found from parameter csv file using Epec Safe Data Validation library’s Calculate16bitCRC function.
16-bit CRC is calculated using following csv columns, in below order:
Parameter OD-index (WORD) in big endian format
Parameter sub-index (BYTE)
Parameter datatype (WORD) in big endian format. CANopen DEFTYPE values (see CiA 301) are used as datatype value for CRC calculation purposes
CSV structure is looped through row-by-row starting from first row. Node-id’s previous CRC value is used as seed and calculation polynomial value is 0x1021 for each step.
Handler’s o_State is Idle if Init was successfully executed. Otherwise either NullPointer or DataError status is given.
Input variable name |
Data type |
Range |
Description |
i_pDevice |
POINTER TO EPEC_CANopen.Device |
≠ 0 |
Used CANopen device (e.g. ADR(G_CANopen_CAN1.Device)) |
i_pCSVData |
POINTER TO CSVData |
≠ 0 |
Pointer to struct array |
i_CSVParCount |
INT |
> 0 |
Amount of parameters in csv data array |
i_Timeout |
TIME |
|
SDO protocol transfer timeout |
Method can be used to get individual node-id’s state.
o_NodeState is DataError if i_NodeID is out of range or Init method is not successfully executed.
Otherwise node-id’s current state is returned.
Input variable name |
Data type |
Range |
Description |
i_NodeID |
BYTE |
1..127 |
Node ID of the control unit which status is returned |
Output variable name |
Data type |
Range |
Description |
o_NodeState |
UniqueIDState |
see enumeration |
Current state for node-id given in input |
Code template definitions: |
|
/// CAN device Device: EPEC_CANopen.Device; |
Code template definitions: |
|
///Number of parameters in network G_NUMBER_OF_PARAMETERS_NETWORK1: INT := 91;
|
Code template definitions: |
|
///Parameter CSV configuration parameters G_NETWORK1_Parameters_CSVData: ARRAY[1..G_NUMBER_OF_PARAMETERS_NETWORK1] OF EPEC_PAR.CSVData;
|
Definitions: |
|
uniqueIDHandler: EPEC_PAR.ParameterCsvUniqueIDHandler; uniqueIDState: EPEC_PAR.UniqueIDState; uniqueIDInitialized: BOOL;
|
Code: |
|
IF NOT uniqueIDInitialized THEN uniqueIDHandler.Init( i_pDevice := ADR(G_CANopen_CAN1.Device), // From code template i_pCSVData := ADR(G_NETWORK1_Parameters_CSVData), // From code template i_CSVParCount := G_NUMBER_OF_PARAMETERS_NETWORK1, // From code template i_Timeout := T#1s ); uniqueIDInitialized := TRUE; ELSE uniqueIDHandler( i_Enable := TRUE, o_State => uniqueIDState );
// Application specific handling IF uniqueIDState <> EPEC_PAR.UniqueIDState.Processing THEN IF uniqueIDState < EPEC_PAR.UniqueIDState.Idle THEN (* Negative value indicates error or ID mismatch, Application can handle the Mismatch or AllNodesMismatch cases *) ; ELSIF uniqueIDState = EPEC_PAR.UniqueIDState.AllNodesOK THEN ; // indicates success on all units END_IF END_IF END_IF |
|
|
Source file topic100521.htm
Last updated 19-Dec-2024