If you’ve done development in TwinCAT for some time, you’ve most likely come across at least one of the OSCAT libraries. These are open source libraries developed in accordance to the IEC61131-3 standard. They provide a total of three different libraries; OSCAT-Basic, OSCAT-Building and OSCAT-Network. I’ve so far only used the OSCAT-Basic library, which provides function blocks and functions for engineering, mathematics, string handling, time/date and much more. There is only a small problem with using the OSCAT-Basic library in TwinCAT – there is a broken reference in it! What follows is a guide on how you can fix this so that you can fully utilize this library in TwinCAT.
This is what it looks like when you download the latest version of the OSCAT-Basic for CODESYS3 (which is fully compliant with TwinCAT3) from their website, install it in TwinCAT3 and reference it in a project:
The OSCAT library holds a reference to a library that doesn’t exist in the TwinCAT3-environment (visualized by the “!”). The library holds a reference to the standard functions in IEC61131-3, called “Standard”. The reference is for a library placeholder that exists in the CODESYS3 environment, but not in TwinCAT3. These standard IEC61131-3 functionality are things like timers (TON, TOF), triggers (R_TRIG, F_TRIG), string functions (LEFT, INSERT, CONCAT) and alike. In TwinCAT3, the placeholder name for the corresponding library is called TC2_Standard. Because the names are different, the library manager of TwinCAT can’t resolve it. So, what do we do?
We need to go to the source of the problem. Because this is a CODESYS3-library, we need to make sure that the library references the “Tc2_Standard” for the IEC61131-3 functionality instead of the “Standard” library. To accomplish this, we need to download the CODESYS3 development environment, open the library in the IDE and change the reference. While we’re at it, we would also want the BASIC-library to reference the version * (latest applicable) instead of a fixed version (which in the current example, points to the Standard library version 18.104.22.168). I’ll show how to accomplish this with the current latest release of the CODESYS3 IDE (V3.5 SP11 Patch 4).
Start by downloading the IDE (which has the catchy name “CODESYS development system V3”) at the CODESYS store. The development environment is (just as with TwinCAT) completely free. Once downloaded make sure to install it. Create a new folder on your hard-drive where you put a copy of the OSCAT-Basic library (oscat_basic_331_codesys3.library). Start the CODESYS development environment. Select “File” and “Open Project…”. Locate the copy of the OSCAT-basic library and open it. Now CODESYS will tell you that it has failed to open library references, which is fine. Just click OK. What CODESYS will try to do now is to download the “Standard”-library from their store to your development environment, which it will notify you by the following window:
You can just skip this and click “Cancel”. If you look at the message window on the bottom of the window you might have noticed the 200+ errors. There you can see all the references to the standard functions from the OSCAT-basic library, such as the call to LEN() in the OSCAT-function UPPERCASE().
What we need to do next is to prepare a reference to the TC2_Standard library. To the left you should have “POUs”. Click on “Library manager” and then on “Library repository”. In the window that now is shown, click on “Install…”. Locate the Tc2_Standard library (located under C:\TwinCAT\3.1\Components\Plc\Managed Libraries\Beckhoff Automation GmbH\Tc2_Standard\X.X.X.X\Tc2_Standard.compiled-library-ge33, where X.X.X.X is any version of the TC2_Standard library on your computer). Make sure to select “All files” as type, otherwise the browser won’t show the library-file. You should now have the Tc2_Standard installed in the CODESYS3 library repository. Close the window.
In the library manager, what you need to do now is to delete the reference to the “Standard”-library by pressing “Delete library”. Now we want to create a reference to the Tc2_Standard library instead. Click on “Add library”, then on “Advanced”. Tick the “Display all versions (for experts only)” tickbox. Go to System->Tc2_Standard and select the version marked with *. Click “OK”. Now go to “File” and “Save project”. You will get a window saying that the project cannot be saved unless the “Released”-flag is removed. Click “Yes” to remove the released-flag.
Now you have a version of the OSCAT-basic library which references the Tc2_Standard library for the IEC61131-3 functions! Now install this library in TwinCAT, and reference it in a project to see the final result:
Looks much better!