Search code examples
plctwincat

How to translate PLC string variable value in TwinCAT HMI TE2000


This question is about the Beckhoff product TE2000 | TwinCAT 3 HMI Engineering. (using v1.12.760.48 | 4024.47)

Within TwinCAT 3 HMI Engineering, it is possible to define translations using keys. These keys are then resolved to a readable string based on the currently selected language, as described here:

https://infosys.beckhoff.com/english.php?content=../content/1033/te2000_tc3_hmi_engineering/2669763595.html&id=88912909674610308

My question is about how to do these translations for dynamic string values.

To give a use-case:

Our PLC code is set-up in a way that a module has a number of parameters. A parameter is a data structure that has all the data available for that parameter (value/min/max/default/etc...) so that it is easy to define these in a uniform way. This way, we can also guarantee the safeguarding of min and max when parameters are set from the PLC code (and not from the HMI).

This parameter instance also exposes a normalized ID, which is basically the name of that parameter within that context.

Doing it this way, also makes it quite convenient to create a user control for this, as is shown below. (the example shows 4 user controls of type ParameterView) Note that the arrows point to the visualized IDs.

enter image description here

This ID is essentially a string parameter, and I do not know how to define a translation for this 'dynamic' string. As far as I could find there is no built-in way to do this.

A valid solution to this could be the following:

  • Define a key of each parameter in the localization,
  • Then create a function LocalizeParameter(parameterId) : Localization to map parameter key to a localization key.
  • Create a function binding using LocalizeParameter(binding to parameter.ID)

Before I go down this route, I would like to discuss if this is the right way forward, and if I am overlooking some built-in mechanism.

Any help on this would be greatly appreciated.


Solution

  • I solved this by using the built-in function GetLocalizedText and then providing the name of the parameter as the key. The localized parameter name is returned if the key is present in the localization tables.

    I do not know if this is the best approach, but it works.