Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY
Purpose of the function block is to update safety parameter index CRC to control unit when parameter index values are adjusted (see also How to adjust safety parameters).
Before adjusting safety parameter index SafetyParCrcHandler’s Init method should be executed.
Init will need safety parameter index list and initial parameter values for whole OD index which is adjusted (see SafetyParReadIndexList (FB) & SafetyParReadIndexData (FB)).
After crc handler is initialized, then parameter value can be adjusted normally (see Parameters_Edit (FB)).
After a sub-index value is changed it needs to be updated for crc handler using UpdateValue method.
When parameter’s adjustment is finished crc handler main block needs to be called with i_Enable set to TRUE. Then following sequence is done:
Set o_State to Processing
Calculate new CRC for safety parameter index using Epec Safe Data Validation Calculate16bitCRC function.
CRC is calculated from first sub-index to last, one sub-index at a time (sub count is excluded).
CRC polynomial 1021h is used (same as CalculateParameterIndexCRC)
o_State is set to DataError and sequence is aborted if error is encountered.
Write new CRC to control unit’s OD index 21FCh. Sub-index is determined with safety parameter index list given in Init.
If CRC update was successful, then o_State returns to Idle, otherwise error code is given.
New parameter from same OD index can be adjusted with same process and CRC updated by setting handler’s i_Enable to FALSE and back to TRUE.
When different OD index or node-id is adjusted, then CRC handler needs to be initialized again.
All safety parameters (each sub-index) shall be included in parameter csv, otherwise CRC will not be calculated correctly. |
CRC is validated in safety control unit using S_ValidateSafetyParameterIndex. To get validated parameters, used parameter types need to abide by safety control unit limitations. |
Input variable name |
Data type |
Range |
Description |
i_Enable |
BOOL |
|
Crc update sequence is started when TRUE |
Output variable name |
Data type |
Range |
Description |
o_State |
SafetyParametersState |
see enumeration |
“Processing” while in progress, returns to “Idle” if successful, see enumeration for error codes |
o_AbortCode |
DWORD |
|
CANopen SDO abort code |
Method is used by application to initialize handler for the OD index which is going to be adjusted.
i_pCurrentValues is list of initial parameter values read using SafetyParReadIndexData.
i_pIndexList is list of control unit’s safety parameter indexes which is read using SafetyParReadIndexList.
i_pCSVData is the data structure which is read with Parameters_ReadCSV.
i_Index needs to be found from safety index list (=is a safety index).
Function block's o_State is set to Idle, if Init is successful. Otherwise error code is returned.
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_NodeID |
BYTE |
1..127 |
Node ID of the control unit |
i_Index |
WORD |
|
OD index which value is adjusted |
i_Timeout |
TIME |
SDO protocol transfer timeout |
|
i_pCurrentValues |
POINTER TO ARRAY [0..255] OF DWORD |
≠ 0 |
Current parameter values for OD index |
i_pIndexList |
POINTER TO ARRAY [1..255] OF WORD |
≠ 0 |
Safety parameter index list |
Method is used by application to update CRC handler’s parameter value list.
Method should be called always after safety parameter value was adjusted with Parameters_Edit.
i_SubIndex needs to be valid for the OD index which was initialized for handler.
Method returns TRUE if it was successful.
Input variable name |
Data type |
Range |
Description |
i_SubIndex |
BYTE |
|
Parameter sub-index to update |
i_pNewValue |
POINTER TO CAA.PVOID |
≠ 0 |
Pointer to adjusted parameter value |
Following example updates safety parameter CRC for selected parameter index.
Selected parameter is determined in application / GUI.
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: |
|
// Array where current values are stored for UI G_ParameterValues: ARRAY[1..G_NUMBER_OF_PARAMETERS_NETWORK1] OF DINT; |
Definitions: |
|
parameterCsvData: EPEC_PAR.CSVData; // selected parameter config indexData: ARRAY[0..255] OF DWORD; (*Values for whole safety parameter index*) safetyIndexList: ARRAY [1..255] OF WORD; crcHandler: EPEC_PAR.SafetyParCrcHandler; pParameterValue: POINTER TO DINT; (*Adjusted parameter value*)
|
Init: |
|
// Same variable pointer should be passed to crc handler which is used with Parameter_Edit(FB) pParameterValue := ADR(G_ParameterValues[10]); // Current parameter value parameterCsvData := G_NETWORK1_Parameters_CSVData[10]; // Selected parameter csv row
// Following assumes that safety parameter index list and index values are already read successfully crcHandler.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_NodeID := parameterCsvData.Node, i_Index := parameterCsvData.Index, i_Timeout := T#1S, i_pCurrentValues := ADR(indexData), i_pIndexList := ADR(safetyIndexList) );
IF crcHandler.o_State < EPEC_PAR.SafetyParametersState.Idle THEN ; // Application specific error handling ELSIF crcHandler.o_State = EPEC_PAR.SafetyParametersState.Idle THEN // Init successful crcHandler(i_Enable := FALSE); END_IF |
When parameter value is adjusted, following code should be used to update value for CRC handler.
Note that actual parameter adjustment is not shown in this example.
Code: |
|
crcHandler.UpdateValue( i_SubIndex := parameterCsvData.SubIndex, i_pNewValue := pParameterValue ); |
After parameter value adjustment is finished, following code should be used to update CRC to safety control unit
Code: |
|
crcHandler( i_Enable := TRUE );
IF crcHandler.o_State < EPEC_PAR.SafetyParametersState.Idle THEN ; // Application error handling ELSIF crcHandler.o_State = EPEC_PAR.SafetyParametersState.Idle THEN ; // Success END_IF |
Parameters_Edit (FB)
Source file topic100516.htm
Last updated 19-Dec-2024