Datatype Worksheet

Datatype worksheets can be deployed with the PLCnext Engineer library and there for being an optional part of the PLM and ACF project types. The plcncli generate config command or in IDE as part of the build process, generates a <libraryname>DataTypes.dt file in the intermediate folder. Each struct, array or enum which is used in a port (directly or nested in a port struct) is listed in the worksheet. The C++ datatypes of the struct, array and enum fields are converted to their corresponding IEC datatype.

Furthermore, a datatype is created for every port of datatype StaticString<...> and StaticWString<...> where the length inside the angle brackets is different from the default length of 80.

The created datatypes have the following structure:

fieldnameStringlength : STRING[length]

fieldnameWStringlength : WSTRING[length]

Fieldname and length are replaced by the corresponding value.

 

The following table shows the default conversion:

C++ datatype IEC datatype
bool BOOL
uint8 USINT
int8 SINT
uint16 UINT
int16 INT
uint32 UDINT
int32 DINT
uint64 ULINT
int64 LINT
float32 REAL
float64 LREAL
StaticString<80> STRING
StaticString<> STRING
StaticString<n> STRING[n]
StaticWString<80> WSTRING
StaticWString<> WSTRING
StaticWString<n> WSTRING[n]
Bit BOOL

Explicit IEC datatype

The IEC datatype can be set to an explicit value by using the //#iecdatatype(<IEC_datatype>) comment.

e.g.

//#port

//#iecdatatype(WORD)

//#name uint16 port1;

 

The following table shows the allowed conversions:

C++ datatype IEC datatype
boolean, bool, bit BOOL
int8 SINT
uint8 USINT, BYTE
int16 INT
uint16 UINT, WORD
int32 DINT
uint32 UDINT, DWORD
int64 LINT
uint64 ULINT, LWORD
float32 REAL
float64 LREAL

Arrays

The array datatypes are generated in different ways:

  • Version 1:

    For PLM projects created with a PLCnext CLI version < 22.6 the array names will be generated like <nameofarray>Array.
    Example: value2Array : ARRAY [0..9] OF INT;

  • Version 2:

    For PLM projects created with a PLCnext CLI version ≥ 22.6 the array names will be generated like ARRAY_<datatype>_<multiplicity>
    Example: ARRAY_INT_0_9 : ARRAY [0..9] OF INT;

If a project has no .proj file in the root directory version 2 will be generated and for ACF projects always version 2 is used, since the generation of dt worksheets for acf was not implemented before PLCnext CLI version 22.6.

Projects < 22.6 can be modified to generate version 2 names instead of version 1 names. To do this the entry <GenerateDTArrayNameByType>true</GenerateDTArrayNameByType> has to be added to the .proj file as a child of the ProjectSettings element.

When using structure members with the same name, this can be useful. But the user should be aware of the fact that changing the array datatype names might lead to errors in existing PLCnext Engineer projects if the old array names were used there before.

Template-based Structs

For templated-based structs the datatype name is generated by replacing all special characters with underscore and replacing the C++ datatypes with the corresponding IEC types.

Example struct:

template<typename Tx, typename Ty>
struct MyStruct{
Tx myValx;
Ty myValy;
}
//#port 
MyStruct<bool, int64> MyPort = {.myValx = false, .myValy = 0};

Example conversion:

MyStruct<bool, int32> will be transformed for the datatype worksheet to

MyStruct_DINT_BOOL : STRUCT
...
END_STRUCT

Further information

If a datatypes worksheet is available, it will become part of the PLCnext Engineer library by default. Generating a datatypes worksheet can be disabled by using the option --no-datatypes-worksheet.

plcncli generate config --no-datatypes-worksheet
plcncli generate all --no-datatypes-worksheet

Restrictions

CHAR, WCHAR, and arrays with more than 1 dimension are currently not supported by PLCnext Engineer. Therefore, in these cases the PLCnext CLI will show an error when a datatypes worksheet generation is requested.

Using structs with same names in different namespaces will lead to a datatypes worksheet with duplicate struct names. We decided, that it is the users obligation to avoid this special case.


• Published/reviewed: 2024-10-30   ☀  Revision 074 •