Hi Asham,
If you’re concerned about users of your libraries accessing the source code, something you can do is export the library as a binary. When someone imports your library into their project, they will not see the source code. However, they will still see
- The declared functions/function blocks within the .fun file
- Any constants declared within the .var file in the library folder
- Any datatypes declared within the .typ file in the library folder
Binary libraries will appear green in the Logical View as B&R libraries do. If you plan to do this, make sure you document your library well and version control your source code! Should you need to make changes later, there is no way to get the original source code from a binary library. And if your library requires functions from any other library in order to work, make sure to list those on the Dependencies page of the library’s Properties.
…is there a way to declare internal functions and function blocks (internally used by the library blocks but are not available for the end user)
Any functions/function blocks declared in the .fun file are useable by the user as this file defines the library’s available functions. If you write a library using C, you can define helper functions directly within the library’s C files without using the .fun file. However, I don’t think this is possible for Structured Text. If you want to use a function block within a function internally, you can declare that function block as an Internal variable within your function like this:
If you’re using custom functions internally and you don’t want to declare them in the same library, you can create a second (or third, or fourth…) library and list it as a dependency to your main library. This library can then hold your helper functions. They’d still be visible to the user, but they’d be in a separate file.
Also, from the set of variables used within the function blocks, can I hide all the internal variables, so that the user can’t see them?
Internal variables declared within the .fun file are always visible to the user. If your library is written in C, you can declare variables within the function/function block/library file and use them without putting them in the .fun file. This essentially hides them if the user cannot access the original source file. Again however, I don’t believe this is possible in Structured Text.
Also, Can I categorize my function blocks within the said library as mentioned below
This seems to work. At the end of the day as long as the compiler can find all of the declarations and implementations it will be able to compile the code. Let us know if you get any errors when you try this. If you export the library as a binary, the end user won’t see the structure anyway.