Library placeholders allow to reference multiple versions of the same library in a PLC project. This situation can be helpful if a library has to be updated in an existing project due to new functions, but the update turns out to give an older FB a changed behavior.
The mentioned problem can be solved by including different versions of the same library in the project using placeholders. Placeholders for libraries are comparable with references. Instead of adding libraries directly to a project, they are referenced indirectly via placeholders. Each placeholder is linked to a library either with a specific version or so that the current library is always used. If libraries are added via the standard dialog, placeholders are always used automatically.
In the following short post, I want to show how to add several versions of the same library to a project. In our example, I will add two different versions of the Tc3_JsonXml library to a project. There are currently three different versions of the library on my computer.
V220.127.116.11 and V18.104.22.168 will be used in parallel in the example.
Open the dialog for adding a library. Then switch to the view Advanced.
Switch to the tab Placeholder and enter a unique name for the new placeholder.
Select the library that will be referenced by the placeholder. A specific version or the latest version can always be selected using the ‘*’.
If you then select the placeholder in the project tree under References and switch to the properties window, the properties of the placeholder will be displayed there.
The namespace has still to be adjusted here. The namespace is used later in the PLC program and is used to address elements of both libraries via different names. I presented the basic concept of namespaces in IEC 61131-3: Namespaces. I chose the same identifiers for the namespace as for the placeholders.
After performing the same steps for the V22.214.171.124 version of the library, both placeholders should be available with a unique name and customized namespace.
The Library Manager, which is opened by double-clicking on References, provides a good overview.
Here you can clearly see how the placeholders are resolved. Usually, the placeholders have the same name as the libraries that are referenced. The ‘*’ means that always the newest version of the library is used, which is available on the development computer. The right column shows the version referenced by the placeholder. The names of the placeholders have been adapted for the two placeholders of the Tc3_JsonXml library.
FB_JsonSaxWriter will be used as an example in the PLC program. If the FB is specified without a namespace when the instance is declared,
PROGRAM MAIN VAR fbJsonSaxWriter : FB_JsonSaxWriter; END_VAR
the compiler will output an error message:
The name FB_JsonSaxWriter cannot be uniquely resolved because two different versions of the Tc3_JsonXml library (V126.96.36.199 and V188.8.131.52) are available in the project. Thus, FB_JsonSaxWriter is also contained twice in the project.
By using the namespaces, targeted access to the individual elements of the desired library is possible:
PROGRAM MAIN VAR fbJsonSaxWriter_Build7 : Tc3_JsonXml_Build7.FB_JsonSaxWriter; fbJsonSaxWriter_Build14 : Tc3_JsonXml_Build14.FB_JsonSaxWriter; sVersionBuild7, sVersionBuild14 : STRING; END_VAR fbJsonSaxWriter_Build7.AddBool(TRUE); fbJsonSaxWriter_Build14.AddBool(FALSE); sVersionBuild7 := Tc3_JsonXml_Build7.stLibVersion_Tc3_JsonXml.sVersion; sVersionBuild14 := Tc3_JsonXml_Build14.stLibVersion_Tc3_JsonXml.sVersion;
In this short example, the current version number is also read out via the global structure that is contained in every library:
Both libraries can now be used in parallel in the same PLC project. However, it must be ensured that both libraries are available in exactly the required versions (V184.108.40.206 and V220.127.116.11) on the development computer.