Search code examples
plciec61131-3

What is the default size of a STRING in IEC61131-3


I inherited a PLC program written in IEC 61131-3 structured text. I just noticed that it has a mixture of STRING variables, and a few STRING(15) variables. It suggests that IEC61131-3 declares its strings with a pre-defined length (does it?) and that there may be a default length (is there?) It makes me wonder if some of the strange string behaviour I have observed comes from strings overflowing their buffers and the excess being ignored (possible?)

Ideally, please support any answer(s) with link(s) to a readily accessible IEC61131-3 reference so that one can browse it for further details of STRING and other IEC 61131-3 data types.


Solution

  • If you declare a STRING variable in IEC61131-3 you always have to specify the length of the STRING.

    sExample : STRING(n);
    

    n determines how many characters/bytes your String has. The \0 character is always appended, so a STRING(n) is n+1 bytes big.

    In Codesys and TwinCat there are some vendor specific specialities that are not defined in IEC61131-3 (afaik):

    sExample : STRING; //This is the same as STRING(80)
    sExample : T_MaxString; //This is the same as STRING(255)
    

    You should not use STRINGs bigger than T_MaxString because the string functions available cannot handle bigger strings.

    This information is based on Beckhoff Infosys TC3, because CodeSys Documentation has no easy access and official IEC61131-3 standard is not freely available. So I can only provide vendor specific information.

    You should recheck this with the documentation from your plc system.