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

Wago-i/o-system 750
Hide thumbs Also See for WAGO-I/O-IPC-C6:
Table of Contents

Advertisement

WAGO-I/O-SYSTEM 750
758-874/000-110 WAGO-I/O-IPC-C6
Pos: 46.9 /Serie 758 (Funk, IPC und PFC)/Feldbuskommunikation/C-Funktionen als CoDeSys-Bibliothek @ 10\mod_1312527555987_21.doc @ 75970 @ 123333323332 @ 1
12
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.
12.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.
12.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 59: "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.
File name of the Linux libraries
The file name of the Linux libraries must begin with lib.
Manual
Version 2.3.0

Incorporation of C-Functions as CoDeSys Library

129

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents