Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

CalculateParameterIndexCRC (FUN)

Description

This function calculates checksum of a CANopen parameter index. The function uses function Calculate16bitCRC internally with parameters i_Seed = 0 and i_Polynomial = 1021h.

 

This function is intended to be used in device that configures safety unit. E.g. a display unit.

 

This function is endianness-aware.

Separate big-endian format conversions shall NOT be used.

 

Supported CANopen parameter index types

Code

Name

Supported

5

Deftype

No. Not used as application parameter.

6

Defstruct

No. Not used as application parameter.

7

Variable

Yes, if the variable type is supported.

8

Array

Yes, if the variable type is supported. Sub-index 0, i.e. the number of parameters is not counted to checksum.

9

Record

No. Record (=STRUCT) members has to be taken in count individually due data alignment and endianness issues.

 

See ParameterDataType table.

 

Limitations

STRUCT type parameter members need to be handled individually due data alignment and endianness issues.

 

BOOL, STRING and REAL are not supported as safe parameters.

 

Inputs

Input variable name

Data type

Range

Description

i_pData

POINTER TO BYTE

≠ 0

Pointer to parameters

i_DataType

ENUM

ParameterDataType

Parameter index data type.

i_NumberOfIndices

USINT

-

Number of parameters in index.

Outputs

Output variable name

Data type

Range

Description

o_OutputValid

BOOL

TRUE/FALSE

Calculated value is valid.

o_ParameterError

BOOL

TRUE/FALSE

Error in input parameters.

Return value

Data type

Description

WORD

Calculated checksum.

Error diagnostic

Conditions

Return value

o_OutputValid

o_ParameterError

i_pData = 0 OR

i_NumberOfIndices = 0

0

FALSE

TRUE

i_pData ok AND

i_DataType ok

Calculated result

TRUE

FALSE

 

Example code

Definitions:

 

SafetyParameterIndexCRCs: ARRAY[0..1] OF WORD := [2(WORD#0)];

 

Index2200: ARRAY[0..24] OF INT := [25(INT#0)];

Index2201: ARRAY[0..37] OF UDINT := [38(UDINT#0)];

 

(* Calculator output statuses *)

sparvalid: BOOL;

sparerror: BOOL;

 

 

 

Init:

 

 

No init.

 

 

Code:

 

 

SafetyParameterIndexCRCs[0] := EPEC_SDV.CalculateParameterIndexCRC(

    i_pData := ADR(Index2200),

    i_NumberOfIndices := USINT#25,

    i_DataType := EPEC_SDV.ParameterDataType.Deftype_INTEGER16,

    o_ParameterError => sparerror,

    o_OutputValid => sparvalid

);

 

IF sparvalid THEN

    SafetyParameterIndexCRCs[1] := EPEC_SDV.CalculateParameterIndexCRC(

        i_pData := ADR(Index2201),

        i_NumberOfIndices := USINT#38,

        i_DataType := EPEC_SDV.ParameterDataType.Deftype_UNSIGNED32,

        o_ParameterError => sparerror,

        o_OutputValid => sparvalid

    );

END_IF

 

 

 

See also

 

 

 

 

Source file topic100390.htm

Last updated 13-Jun-2024