Incorporation Of C-Functions As Codesys Library; Example For Linking A Dynamic Library; Developing And Compiling A Linux Shared Library; Figure 93: "Libmytest.c" File - WAGO -I/O-SYSTEM 750 User Manual

Wago-i/o-ipc-c10e 758-875/000-112 canopen master codesys 2.3
Hide thumbs Also See for WAGO-I/O-SYSTEM 750:
Table of Contents

Advertisement

138

Incorporation of C-Functions as CoDeSys Library

13
Incorporation of C-Functions as CoDeSys
Library
For the use of any C- or also Linux functions in CoDeSys, the import interface
described in the following is available. This can be used to load and use Linux
libraries dynamically into the CoDeSys runtime system.
13.1

Example for Linking a Dynamic Library

The following section will explain to you by means of an example the procedure
for linking a dynamic library using a C-function in CoDeSys.
13.1.1

Developing and Compiling a Linux Shared Library

Before you can use C functions within a CoDeSys program, you must develop and
compile a Linux shared library. Proceed in the following manner:
1.
Create a file with the necessary functions. In this example, the file
"libmytest.c" was created for this purpose with a "MyTestFunction"
function and "unsigned short" data types.
#include <stdio.h>
unsigned short MyTestFunction(unsigned short value)
{
return value+=2;
}

Figure 93: "libmytest.c" file

2.
Compile and link the file by entering the following command in the Linux
console:
gcc libmytest.c -Wall -shared -o libmytest.so
In Linux, the parameter "-shared" must be used when calling up the "gcc"
compiler.
With an error-free compilation of the file, a dynamic library "libmytest.so" is
generated with the parameter "-shared" that contains the "MyTestFunction" C-
function.
The file name of the Linux libraries must begin with lib.
Note
WAGO-I/O-SYSTEM 750
I/O-IPC-C10E, CANopen Master

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents