2

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.

omatai
  • 3,448
  • 5
  • 47
  • 74
  • The question in your second paragraph is off-topic according to item #4 in the [help/on-topic]. You may want to remove it to avoid close and/or down votes. – Ken White Sep 13 '16 at 03:21
  • Duly edited to change emphasis - there should be a definitive answer to this question, and one source that proves it will be sufficient. I certainly can't find one after more searching than I can tolerate. – omatai Sep 13 '16 at 05:08

2 Answers2

4

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.

Felix Keil
  • 2,344
  • 1
  • 25
  • 27
  • Agreed: IEC61131-3 is not freely available. I imagine it specifies that all strings have a fixed maximum size, and therefore if you concatenate two strings, there will never be any further memory allocation, and the result will be truncated if necessary - can you confirm this? – omatai Sep 15 '16 at 00:13
  • 1
    In TC3, the _Standard_ library string functions are limited to 255 characters, but you can work with longer strings by using the [extended string functions](https://infosys.beckhoff.com/content/1033/tcplclib_tc2_utilities/63050398266130955.html?id=2610871641110492978) in the _Utilities_ library (CONCAT2, FIND2, INSERT2, DELETE2, REPLACE2, etc). These work using `POINTER` and `SIZEOF`, so they can handle strings of any size. Bear in mind that copying large strings should be avoided in tasks with fast cycle times. – Hydrargyrum Feb 11 '20 at 07:29
1

If a size is not defined, then CODESYS allocates 80 characters by default.

https://help.codesys.com/api-content/2/codesys/3.5.12.0/en/_cds_datatype_string/

jackal_rs
  • 31
  • 2