User Documentation
Table Of Contents
- Table of contents
- 1 Introduction
- 2 Safety instructions
- 3 System overview
- 4 Operating behavior
- 5 Software installation
- 6 Configuration
- 7 Program development
- 8 Licensing
- 9 Device Administration (DevAdmin)
- 10 Software units
- 11 OPC UA Server
- 12 Node-RED
- 13 LongtermDiagnosticMonitor
- 14 Data recorder
- 15 Diagnostics
- 16 Maintenance
- 17 Technical data
- 18 Directives and standards
- 19 Appendix: Tutorial - creating an IEC project
- 20 Appendix: Addressing in the Ethernet (basics)
- 21 Appendix: Tutorial FoE
- 22 Appendix: Tutorial - call C function from IEC
- Index

Appendix: Tutorial - call C function from IEC
System manual
2696790000/02/04.2020
126
struct func1_Instance {
int32_t *inst_global;
};
In addition both files stdio.h and string.h must be included.
To create the C function the file MyIEC_C_Call.c under myIEC_C_Call ►
src in the project tree must be opened in the working area. The program
code in the function int func1(...) is removed and replaced with the fol-
lowing code parts.
In the first code line the variable char msg [106] is defined. This variable is
used later to buffer a text.
In the next codeline the values of the input parameters (addresses of the
memory area) which are delivered when calling the C function are displayed
in the Trace Monitor of u-create studio .
printf("func1 (called from IEC) with params: in_dword:%i, in_string:%s,
in_real:%f \n", *(in->in_dword), in->in_string, *(in->in_real));
In the next lines the calculation is executed.
First the variable inst_global is added to the variable in_dword:
*(inst->inst_global) += *(in->in_dword);
Then the variable in_real is multiplied with 3 and the result is assigned to
the variable out_dword:
*(out->out_dword) = *(in->in_real) * 3;
In the next step a text consisting of the variable in_string and additional
characters is written to the variable msg. Then the content of the variable msg
is copied to the variable out_string.
sprintf(msg,"C-Function answering to \"%s\" .", in->in_string);
strcpy(out->out_string , msg);
In the end the variable in_dword is multiplied with 2 and the result is re-
turned as return value of the function.
return *(in->in_dword) * 2;
The C function has been created.
Now the project is build via Project ► Build All in the manu bar and the out-
put (libMyIEC_C_Call.so) is loaded to the control in the directory /appld-
isk/application/control/ccontrol/ via Download.
22.4 Calling the IEC funtion in the IEC application and download
In the IEC application the created IEC funtion can be used. Therefore a pro-
gram (e.g. PLC_PRG) in u-create studio is extended with the following code:
Local variables
VAR