Creating a “Hello World” Application

  1. In the tree view right-click on App node and add a new object.

    ../_images/fabbc74231b2ed460a317f344964fa05
  2. In the following dialog select C_Code_App and click Add object.

    Select the compiler to be used for the new C/C++ application and click Add.

    ../_images/6b885768174071570a317f342e485690
  3. In the following dialog select POU and click Add object.

    ../_images/509793318c276c560a331390019bf77c
  4. Select the type for the POU object and click Open.

    ../_images/fe3aede531ef0ca20a317f3442ac7c96
  5. Enter a parameter and variable declaration.

  6. Right-click at the desired code position and select Input Assistant in order to define the data type:

    ../_images/4a32cd4831f229930a317f3410c9ea29
  7. Then, click Apply to update the interface. As an alternative the interface can be displayed tabularly. Tabular view is a comfortable way to edit parameters:

    ../_images/57919da631f95a6f0a317f3405213e26
  8. On the C_Code_App tab open the Compiler options tab. Select a compiler and configure compiler settings for the C/C++ application. These settings enable the compiler to interprete and process the source files listed on the C-Code tab.

    ../_images/5a70af4931ff46220a317f344866eb7d
  9. Open the C-Code tab. The following files are listed:

    • C_Code_App.c: Implementation of POU.
    • C_Code_App.h: C/C++ Interface of POU.
    • C_Code_App_Init.c: Initialization of POU variables and parameters.
    • C_Code_App_Shell.c: Main module.
    ../_images/5789e3be320642580a317f344994520e

    Note

    Double-click the Folder icon to open the directory in Windows Explorer.

  10. To edit the POU implementation double-click or right-click a file and select Open…). The *.c and *.h files are opened in your operating system’s default editor.

    ../_images/7b75ed14320805480a317f346bc37518
  11. Save your settings and click Compile on the right side of the screen. The object files are generated from source code. Compilation errors are reported within a message window. Details on the error can be found in the compiler.log file.

    ../_images/02d5e5628c27b9550a33139000a73b56
  12. Save your project. In the tree view double-click Application. CODESYS is started with C/C++ interface. From the C_Code_App node an external library is generated. This library can be found in CODESYS 2.3 in the Library Manager.

  13. Call the C/C++ code POU from your IEC application.

    ../_images/4fefe0a6322554c30a317f3424a5b900

    Note

    In order to lookup C/C++ POUs, press F2 and open section Standard Functions / Standard Function Blocks .

  14. Build the project via Project ‣ Build: C/C++ application parts are linked together with IEC application.

    Application is ready for download.