With the CODESYS Control SL Extension Package, you can implement your own functions in C and call them from the IEC application.
For this connection, the C code is integrated into the runtime system in the form of a separate dynamic component (shared object).
There is one way to include:
-
Prepared on the controller: The dynamic component is already configured to the CODESYS runtime system (a
shared objectexists and is configured on the Linux system). Then, only the respective IEC library is required.
The following describes how to create the library and the dynamic component.
Development Environment
-
Open CODESYS and create a new library.
-
Set the title of the library(Project Information, Summary tab) and save the library under the same name.
-
Add the desired functions and mark them as External implementation.
-
In the context menu of the function in the project navigator, click Properties. On the Build tab, select External implementation.
-
Note: The function has to contain "
_cext" in the name.
-
-
Now generate the *c and *m4 files:
-
Click Build → Generate Runtime System Files.
-
Select M4 interface file and C stub file.
-
Select the save location.
-
Linux
-
Download the CODESYS Control SL Extension Package with the CODESYS Installer.
-
Download the Yocto BSP VM (ftp://kontron_pub:WENZtA6i@ftp.kontron.ch/WebPanel/SDK/)
-
Execute the Yocto BSP VM
-
Copy the Extension SDK to the Yocto BSP VM system which has the corresponding compile environment for the target system.
By default, you find the Extension SDK under:
C:\Users\<windows username>\CODESYS Control SL Extension Package\<version>\ExtensionSDK. The directory will be referred to as "<SDK DIR>" in the following steps. -
Create a new folder where you create the C implementation. This folder is in the following
<PROJECT DIR>. -
Open a Terminal and call:
$ /opt/kontron/40099086/0B/environment-setup-armv7at2hf-neon-ktn-linux-gnueabi -
Navigate to
<PROJECT DIR>and run:$ make -f <SDKDIR>/makefile newproject -
Copy the *c and *m4 files you created in the Development Environment to
<PROJECT DIR>. -
Implement the functions in C.
-
Create the shared object:
$ make allThe
shared objectis generated and located in<PROJECT DIR>/out/libCmpMyTest.so.
As a result, you have created a dynamic component which can now be called from the IEC application via your IEC library. Details about the build process (make) can also be found in the makefiles and README file in the Extension SDK.
Now include the component:
Including the dynamic component on the target device
This method allows you to include the shared object previously created in C into the runtime system. No additional system permissions are required for the user and the library can be rolled out to the devices using familiar methods.
-
Copy the shared object created above to the runtime system.
-
Copy the shared object to
/usr/lib/or an equivalent library directory where libraries are found by the system. -
Stop the runtime system (example:
$ /etc/init.d/codesyscontrol stop) -
Open
/opt/codesys/CODESYSControl_User.cfg:$nano /opt/codesys/CODESYSControl_User.cfg -
In the
[ComponentManager]section, add the created shared objects:Bash[ComponentManager] Component.1=CmpFirstTest Component.2=CmpSomeOtherComponent ...Note: The number is a incremental number which must not conflict with existing components.
-
Start the runtime system:
$/etc/init.d/codesyscontrol startNow you can check whether the component has been loaded in the codesys log
Example
|
Description |
File |
|---|---|
|
CODESYS Library with External Functions |
|
|
CODESYS Test Application |
|
|
CODESYS Dynamic Component Sources |
Restrictions:
-
With the Extension SDK, only C code can be included.
-
A debugger cannot be use to examine or debug the C code (for example, as in the programming system).
-
The C code cannot "interact" with the runtime system or the IEC application. This means:
-
Automatic access to variables of the IEC application is not possible.
-
Access to functionality of the runtime system is not possible. However, access to variables of the IEC application are of course possible by passing them to a function implemented in C code
by reference(for example, viaPOINTER).
-
Further information:
https://content.helpme-codesys.com/en/CODESYS%20Examples/_ex_extension_package.html