OSCAT basic library in TwinCAT

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:

OSCAT-Basic in TwinCAT

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 3.3.0.10). 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:

CODESYS library download

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().

CODESYS message window

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:

OSCAT-Basic in TwinCAT fixed

Looks much better!

Mobile coding icon by Freepik from www.flaticon.com
Old books by Jarmoluk from www.pixabay.com

  • Share on:

18 Comments, RSS

  1. Mark

    Another great post, Jakob. Is there any chance you can post your TC ready version of OSCAT basic on github?

  2. Marty

    Thanks a lot! Great tip! Oscat basic installed succesfully to Twincat3.

    This made me thinking. Can i use this same method if i want to use Codesys visualization libraries in TC3 ?

    • Jakob Sagatowski

      Happy that this has helped you Marty!
      That is a good question. I thought the visualization libraries in TwinCAT3 versus the ones in CODESYS3 were more or less the same. I’ve only used the visu-libraries in TwinCAT to do some quick “engineering” visualizations for tests. It’s definitely worth an investigation!

      • Marty

        Why I asked this is that there’s some user created visu symbol for codesys which are not available for twincat

  3. Massimo Confalonieri

    In my project I use various Function Blocks and I would like to protect them by turning them into the Compiled Library.
    In my program I also use the TC2_MC2 library which is called in my Function Block. I can’t import this library into “CODESYS development system V3”.

    The error is as follows:
    “The specified library is not a managed library. (Reason: Project Information not found.)”.

    How can I do? Is there a solution to this problem?

    Thanks in advance
    Massimo

  4. Alex

    Hi,
    i know that this great post is quiet old, but i am stuck in converting the oscat_network.lib.

    Codesys is not able to open the .lib file i downloaded from the oscat website because it is expecting a .library.

    Can anybody help to make the oscat_network.lib running for TC3?

    Thank you in advance!

    Greetings,
    Alex

  5. Don

    Hi Jakob,

    Thank you for the tips here. I am attempting to import the latest Oscat basic library into the latest version of Codesys (V3.5 SP15 Patch 3 (32-bit)). Codesys is expecting a .library extension when opening a project. I figured that was simple enough as I just changed the Oscat library extension from .lib to .library and now Codesys sees it fine. However…..when I attempt to open the library in Codesys as you describe, Codesys is throwing the error “File is corrupt”, possibly because I changed the Oscat library extension name (?). Can the described method of importing the Oscat library still be done, or is there now a different way. My end goal is to be able to use the Oscat library in TwinCAT 3.

    Thanks,
    Don

  6. Ivan.Zeng

    Hi,I tried to use TC2_Standard in CoDeSys, but it will report an error: gobal_ version ST_ Libversion is not defined. Do you have any good ideas? Thanks

  7. Adam

    Hye jacob!
    Thanks for your post. I finally managed to solve my problem with the existing oscat basic 3.3.1 in my turck plc library..

    I followed your step except for the selection files from the TwinCAT folder though..thank you!!

  8. Alireza

    Hi Jakob,

    When I want to install AixOCAT on TwinCAT 3 using the Library repository “Install” button it gives me this error “The specific library is not a managed library(Reason: Project information not found.)”

    Please help me to install this library.

  9. Marshall

    Hello Jakob,

    For my version of the CODESYS IDE (V3.5 SP20), I didn’t have an “Advanced” option in the “Add Library” dialogue. Instead, I had to go to “Placeholders” → “Other library…” → Check “Display all versions(for experts only) → Select (Miscellaneous) \ Tc2_Standard \ *.

    Your website and videos are such excellent resources for those new to structured text and TwinCAT.

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.