Entering code within the C-block or C++-block (deprecated)
How to enter the C-code or C++-code in your →blocks and use them within →ST:
As preparation, set the correct build configuration: context menu of the project, select Build Configurations, Set Active and the command for the corresponding platform
Without this preparation you will not be able to use the logi.CAD 3 functions to navigate within the libraries to be used.Double-click the file LCfu___name.c or LCfu___name.cpp displayed in the project explorer.
This file has automatically been created by logi.CAD 3, when you have created the interface for the C-block or the C++-block.In the opened file, enter the required C-code or C++-code.
Use a This Pointer for accessing variables as well as in-/outputs (for function blocks) or outputs (for functions) that you have declared for the interface. Enter all names in upper-case letters.
For functions, the access to inputs is done without using a This Pointer.Example for accessing input/output of the function block#define V(VAR) (LC_this->LC_VD_##VAR) /* C-macro for a simplified access to parameter */
/* ... */
V(OUT) = V(IN1) + V(IN2); /* your C-code within the C-file for the function block */
Example for accessing input/output of the function#define V(VAR) (LC_this->LC_VD_##VAR) /* C-macro for a simplified access to parameter */
/* ... */
V(OUT) = LC_VD_IN1 + LC_VD_IN2; /* your C-code within the C-file for the function */
V(MYCFUN) = LC_VD_IN1 + 1;
Restriction for C-blocks
Do not enter any comments in C++ style for C-block. See the FAQ-article "May I comment my C-code?" for details.
Use POU-unique names (when possible, project- and POU-unique) for all C-identifiers that are available in a global namespace. See "The dos and don'ts when working, When creating blocks with C-code" for details.
Save the file with your C-code or C++-code.
Repeat the steps for each file in which you want to enter C-code or C++-code.
Use the function blocks and functions within your application (e.g. with the →program that has been declared within an ST-object without {extern_c} or {extern_cxx}):
Required only for function blocks: Declare the required →function block instances. The necessary syntax is listed under: "Declaration of function block instances in ST"
Required for function blocks and functions: Enter the calls of the blocks. The necessary syntax is listed under: "Calls in ST"
Save the ST-object with your application.
If you load the application onto the PLC now, the defined code of the C-block or C++-block is included.