Codesys 3. How to get the translations from static or dinamic text file in ST?

1.2k views Asked by At

I am using Twincat 3 (4024.10) and I tried the functions "GetTextByStringId" and "GetText" from the library SysLibTargetVisu but the compiler already gives me an error:

Error Unresolved reference: 'GETTEXTBYSTRINGID' 0

It seems that in Codesys 2 works: https://forge.codesys.com/forge/talk/CODESYS-V2/thread/8f2fc2e158/

Thanks in advance!

2

There are 2 answers

5
Filippo Boido On

I remember wasting my time on that too. Unfortunately it seems to be an old undocumented and unmantained library.

I resolved the issue in a couple of hours by writing an xml reader in Java that reads the ids and the texts from the textlist and pushes them over ads to the plc where they are stored in memory. The values can then be used as needed.

The other advantage from this approach is that you do not dipend on the plc hmi license.

0
Daniel Müller Navarro On

I found a solution at the library VisuElems. It actually works. This is the function:

FUNCTION F_GetText : STRING
VAR_INPUT
    sTextList : STRING;
    sId : STRING;
END_VAR

sTextList := CONCAT('Port_851.',sTextList);
F_GetText := VisuElems.CmpDynamicText.DynamicTextGetText(
    pstTextList:= ADR(sTextList), 
    pstTextIndex:= ADR(sId)
    )^;

And at the program we call it like this:

sTest := F_GetText(sId := 'maschine', sTextList := 'TL_Visu');

You might want the default translation. Lets say the default translation is german and we have the constant:

DE: STRING(8) := 'default';

The function is:

sTextList := CONCAT('Port_851.',sTextList);

IF VisuElems.CURRENTLANGUAGE = DE THEN
    F_GetText := VisuElems.CmpDynamicText.DynamicTextGetDefaultText(
        pstTextList:= ADR(sTextList), 
        pstTextIndex:= ADR(sId)
        )^;
ELSE
    F_GetText := VisuElems.CmpDynamicText.DynamicTextGetText(
        pstTextList:= ADR(sTextList), 
        pstTextIndex:= ADR(sId)
        )^; 
END_IF

I got with this solution from this german webpage: https://www.sps-forum.de/archive/index.php/t-88760.html