Generating Application Code

The application code is the machine code that a PLC executes when you start an application.

CODESYS automatically generates the application code from the source code that was written in the development system. This is done automatically before downloading the application to the PLC. Before the application code is generated, a test is performed for checking the assignments, the data types, and library availability. In addition, the memory addresses are allocated when the application code is generated.

You can execute this command explicitly by clicking Build ‣ Generate code . This is useful for detecting any errors in your source code, even when the PLC is not connected yet. The errors are printed to the message view (“Build” category).

Hint

If you have encrypted the application, then consider the following information: If a (new) boot application generated on request after an online change, then the boot application is formed in the RAM with the current code that is NOT encrypted.

Explicit generation of application code

Requirement: The application can be compiled without any errors.

  1. Click Build ‣ Generate code .

    ⇒ The application code is generated. Detailed information about memory allocation is printed in the message view.

See also

Messages when generating application code

When you generate application code, CODESYS prints information about memory allocation in the message view. Gaps arise in the memory because reallocation is only for new and changed blocks and variables due to the incremental memory compile. Online changes have the same effect. This fragmentation reduces the amount of available memory. However, you can completely reallocate the memory by clicking Clean and therefore increase the amount of free memory.

More information about messages at code generation: Syntax errors and errors that CODESYS detects during code generation and memory allocation appear in the message view in the Build category. At each code generation, information is also provided about the code size, the data size (in bytes), the contents of the allocated memory, and the highest address used (byte). It depends on the PLC which data and code is stored in which memory areas. For example, code and data is located in the same area on the CODESYS Control Win V3. For the addresses %I, %M, and %Q, memory is always reserved, even when a variable is not assigned to an address. After cleaning the application, the memory is reassigned completely. In this case, small gaps may result from the predefined alignment (normally 8). Larger gaps result from changing a date without cleaning, for example increasing an array range. In this case, only the affected POUs are rebuilt. Online changes have the same effect. Resulting gaps are reused when possible for other changes. As small gaps can no longer be used at all in some cases, the size of the “largest correlating memory gap” of the affected memory area (in bytes) is issued as meaningful information for the current code generation, as well as its percentage of the total memory.

Please note the options for generating applications.

See also