Skip to main content

Application on the PLC

Downloading the application to the PLC

Requirement: The application has been compiled without errors.

For more information, see: Debugging the application program

  1. Click Online → Login.

    A dialog prompt opens to ask whether or not the application should be downloaded to the controller.

  2. Click Yes.

    The application is downloaded to the controller. The entries for the controller and the application in the Devices view are highlighted in green. Stop appears after the Application object. The current status of the controller _cds_icon_stop_in_status_bar.png is displayed in the taskbar.

Starting the application

If you have followed this tutorial precisely up until now, then you can use the Application on the PLC Device (CODESYS Control Win) .

  • In the Devices view, in the context menu of the Application object, click Start.

    The program is running. The entries for the controller and the application in the Devices view are highlighted in green. Run appears after the Application object. The current status of the controller _cds_icon_run_in_status_bar.png is displayed in the taskbar.

Monitoring and one-time writing of variable values at runtime

In the following section, you can view the "monitoring" of the variable values in the various POUs, and you can set a specific variable value on the controller one time only from CODESYS.

You can see the actual values of the application variables in the online views of the POU editors or in monitoring lists. In the example here, we will focus on monitoring in the POU editor.

Requirement: The application is running on the controller.

  1. In the device tree, double-click the objects PLC_PRG, Signals, Simulation, and Glob_Var to open the online views of the editors.

    In the declaration part of each view, the actual value of the variable (1) on the controller appears in the table of expressions in the Value column (3) (see figure).

    _cds_img_tutorial_refrigerator_monitoring.png

    Monitoring in the implementation part depends on the implementation language. In the case of non-Boolean variables, the value is always located in a rectangular field to the right of the identifier. In the ST editor, this also applies to Boolean variables. We call this display "Inline monitoring". In the graphical editors, the value of a Boolean variable is shown by the color of the output connecting line (black for FALSE and blue for TRUE):

    _cds_img_main_tutorial_booleans_in_cfc.png
  2. Observe how the variable values change in the various POUs. For example, you can see in the GVL Glob_Var how the values of rTempActual and xCompressor change due to the processing of the simulation program.

One-time setting of variable values on the controller:

  1. Set the focus in the online view of the GVL Glob_Var.

  2. To set a new specified value, double-click in the Prepared Value column (2) next to the expression rTempSet.

    An input field opens.

  3. Specify the value 9 and exit the input field.

  4. To specify an open door, click once in the Prepared Value field next to the expression xDoorOpen. The value TRUE is specified. Click three more times to see that you can toggle the prepared value between TRUE, FALSE, and empty.

  5. To write the prepared value TRUE one time only to the variable, press Ctrl+F7.

    The two values are each transferred to the Value column (3). Now the variable xDoorOpen no longer changes its value and the set temperature is 9 degrees. The timTemp variable changes to the value 1s because the refrigerator door is now "open" and the heating due to the Simulation should be faster than before (2s).

Setting of breakpoints and stepping at runtime

"Debugging": For troubleshooting purposes, you need to check the variable values at certain points in the code. You can define breakpoints for the execution and initiate a step-by-step execution of the statements.

Requirement: The application has been downloaded to the controller and is running.

  1. Double-click Simulation to open the program in the editor.

  2. Place the cursor in the code line iCounter := iCoutner + 1; and press F9.

    The _cds_icon_breakpoint_activated.png symbol is displayed before the line of code. It indicates that a breakpoint is set on this line. The symbol changes immediately to _cds_icon_breakpoint_halt.png. The yellow arrow always points to the next statement to be processed. _cds_icon_halt_on_bp_iin_status_bar.png appears in the taskbar instead of _cds_icon_run_in_status_bar.png.

  3. Observe the value of the variable iCounter in the inline monitoring or in the declaration part of the Simulation program.

    The value of the variable no longer changes. The processing was stopped at the breakpoint.

  4. Press F5 to restart the processing.

    After one cycle, the program stops again at the breakpoint.iCounter was incremented by 1.

  5. Press F8 to execute the next processing step.

    The RETURN at the end of the line iCounter := iCounter + 1; statement is highlighted in yellow.

  6. Press F8 again to execute the next processing step.

    The processing jumps to the editor of PLC_PRG. Repeatedly pressing F8 shows how the program is executed step-by-step. The statement to execute is once again marked each time with a yellow arrow.

  7. To disable the breakpoint and return to normal processing, set the cursor back in the code line and press F9. Then press F5 to set the application back to _cds_icon_run_in_status_bar.png mode.

Executing a single cycle at runtime

Requirement: The application has been downloaded to the controller and is running.

  1. As above when stepping, monitor the line iCounter := iCounter + 1; in the Simulation program.

  2. Press Ctrl+F5 or click Debug → Single Cycle to run a single cycle.

    The processing runs through one cycle and stops at the breakpoint again.iCounter was incremented by 1.

  3. Press Ctrl+F5 a few more times to view single cycles. Then press F5 again.

    The program runs again without stopping and without forced values. The temp variable has the value 1s again. _cds_icon_run_in_status_bar.png is displayed again in the status bar.