I like to have things structured and ordered. This does not only include the obvious stuff as making sure to pair and match all socks after laundry, but it also includes the TwinCAT software I develop, more specifically own developed TwinCAT libraries. “Whaaat??? What does sorting socks have to do with TwinCAT software?” you might wonder. I’m glad you asked.
One of the things that have always annoyed me is that own developed libraries always go into the category (Miscellaneous) when using the Library Repository browser:
Notice how our MyCoolLibrary is put under (Miscellaneous), while the Beckhoff libraries are all well ordered and sorted? Now after you’ve developed some libraries for a while it’s going to get really messy in the (Misc)-category. Why is that our libraries are put there and the Beckhoff ones are not? The reason is spelled Library Categories. If you enter the properties of your PLC project you will see that the field Library Categories is empty.
If you click on the … and then on Add > you have the choice of either defining a category from:
- From other library which means that the definition will be copied from a library that is already installed on your system
- From description file which means that you need to provide a XML-file with library definitions of your own choice
The first choice is good to use if you for instance want to use an existing librarys category. The only problem is that this selection can only be done on non-compiled libraries (i.e. libraries having a file extension of .library). All Beckhoffs libraries are compiled libraries (ending with .compiled-library) as Beckhoff don’t want the source code to be easily available and thus we can’t access the library category for those libraries. If we are doing this for the first time we’re left with option number two. Selecting from description file opens up a window where we can select a file having the file extension .libcat.xml. Now how do I know what this file should look like? Searching my whole C-drive for files with this extension gives me a total of zero finds. A quick e-mail to the local Beckhoff support, an equally quick response and now I’ve got something to start with.
The library categories can be defined using the follow definition file:
<?xml version="1.0" encoding="UTF-8"?> <LibraryCategories xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="LibraryCategories.xsd"> <LibraryCategory> <Id>4c30be10-0c29-4796-921e-62ecfda40191</Id> <Version>22.214.171.124</Version> <DefaultName>MainCategory</DefaultName> </LibraryCategory> <LibraryCategory> <Id>e42e9899-3114-40a3-911f-5f44e2769932</Id> <Version>126.96.36.199</Version> <ParentCategory> <Id>4c30be10-0c29-4796-921e-62ecfda40191</Id> </ParentCategory> <DefaultName>SubCategory</DefaultName> </LibraryCategory> </LibraryCategories>
What we’ve basically got here is a file defining all the categories (and optional) subcategories for your libraries. You define a category by a name, version number (which I always set to 188.8.131.52) and a GUID. I use this GUID generator to come up with the IDs. If you want to define a subcategory you refer to it with the <ParentCategory>-tag and put the same ID as the parent category inside of the tag such as:
If you want to have a subsubcategory below SubCategory you can continue like this by defining a new ID for the new subsubcategory and setting the parentcategory-ID to the subcategory. Now that we have a file defined, how does it look like if we load it using From description file…?
More or less what we would expect. Funny thing is that it’s possible to select both the main category “MainCategory” and “SubCategory” at the same time. Doing so and installing the library gives us:
I don’t see any use case for why one would want to install a library at a main- and subcategory at the same time. Oh well, now you know how to accomplish the category definition and selection. I’ve put the template described in this post for the libraries categories on my GitHub.
Update: Since posting this I’ve been notified that Nikolai has library categories for TwinCAT (including older versions than 3.1) on his GitHub as well. While you’re at it, I highly recommend you visit his excellent TwinCAT blog.