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>184.108.40.206</Version> <DefaultName>MainCategory</DefaultName> </LibraryCategory> <LibraryCategory> <Id>e42e9899-3114-40a3-911f-5f44e2769932</Id> <Version>220.127.116.11</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 18.104.22.168) 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.
Socks icon by Freepik from www.flaticon.com
Old books by Jarmoluk from www.pixabay.com
Thank you very much for this article. Helped me in creating a library with proper descriptions.
Is there any way to do this with when installing the custom library to a different repo location? I can only get the proper category format when installing under the default “System’ repo.
Thanks! It didn’t work at once.
1. There are two variations of the XML-file in the internet: one with curly braces around the GUIDs and one without. According to Beckhoff the GUIDs should NOT be surrounded with curly braces.
2. I placed the XML-file at solution file level to be able to put it under source control. Beckhoff states it should be saved under ‘C:\TwinCAT\3.1\Components\Plc\Managed Libraries’. I moved it to there, then it worked. I moved it back and it kept working.
Currently I have no time to investigate the real cause that it didn’t work at once. If somebody knows more, please go ahead.
how to add my own library help document?when i double clik a Function block of my lib in TC
3,i can see its help text in reference window?