Skip to main content

Working with the Simulation Interface

Preparations

When getting started with the simulation interface, it is helpful to configure the local environment with two CODESYS controllers.

Tip

The easiest way to do this is to download the two CODESYS Control Win SL controllers from CODESYS Store International. You will find the product and the data sheet for the product in the CODESYS Store International or in the CODESYS Store North America. The ZIP file contains the 64-bit and 32-bit version of CODESYS Control Win SL.

  1. Installing the packages

    1. Install the CODESYS Simulation Interface add-on in your CODESYS programming tool.

    2. Install the CODESYS Simulation Interface Example package.

      The CODESYS Simulation Demonstrator add-on is part of the package.

    3. Install and open the SimulationInterfaceExample.projectarchive sample project.

  2. Install the two runtime systems.

  3. Open a standard project with a CODESYS Control Win 32-bit device. Start the gateway and the device.

  4. In the Devices view, double-click this device.

    The device editor opens.

  5. Click the Scan Network button.

    The CODESYS Control Win 32-bit runtime environment is displayed.

  6. Select the device and configure it as usual.

    The device is connected.

  7. Select the command Change Runtime Security Policy and click Yes to confirm the next dialog.

    Communication settings

    _simitf_communication_settings_change_runtime_security_policy_.png
  8. Configure the device user management.

  9. In the Change Runtime Security Policy dialog, set the device user management from Enforced user management to Optional user management.

  10. Enable the Allow anonymous login option and click OK to confirm the settings.

  11. Click the Device button and select the Rename Active Device command and rename the active device in the next dialog.

    _simitf_communication_settings_rename_active_device.png
  12. Specify a new device name (example: SimBroker).

  13. Update the device to the device description CODESYS Control Win x64.

  14. Repeat from Step 3, but rename the device as SimTarget.

    Ready.

Simple example

To familiarize you with the simulation interface, a simple example is developed step by step. Imagine a machine whose I/O data is exchanged via a fieldbus. A PROFIBUS is used as the fieldbus.

  1. Create a new standard project and select the 64-bit device CODESYS Control Win as the device type of the simulation target.

  2. Double-click the device.

    The device editor opens.

  3. Configure the following:

    1. Add an Ethernet adapter.

    2. Add a PROFINET Controller.

    3. Add an 8-bit input.

    4. Add an 8-bit output.

  4. Declare two byte variables in PLC_PRG and use the variables in your application code.

    byIn, byOut

  5. Assign the variables to an input and an output.

  6. Generate the code.

    In the best case, the build is executed without errors.

    You now have the following device tree:

    _simitf_img_devicetree.png

    This is the application we want to simulate.

Use the following steps to add the simulation interface. You configure these to simulate the application.

  1. Select the application and select the Add ObjectSimulation Interface command in the context menu.

  2. In the next dialog, click the Add command.

    The simulation interface has been added and can now be configured.

  3. For these first steps, leave the default values unchanged and only adjust the IP address of the device. Specify the local address (example: 192.168.178.47).

  4. On the Configuration tab, set the Simulation Options setting to Mapped I/O signals only.

  5. Select the Simulation enabled option.

  6. Switch to the Simulation Broker tab.

  7. Click the Select Broker Device button.

  8. Select Gateway-1 and click the Scan Network button.

    The SimBroker and SimTarget devices are displayed.

  9. Select the SimBroker device.

  10. Click the Update Broker button.

  11. Wait until the message Simulation broker successfully updated is displayed.

  12. Log in to the SimTarget device.

    _simitf_ua_expert_infomodell.png

This information model can now also be scanned by the software to get information about the existing simulation targets and the information model used. The CODESYS Simulation Interface Example add-on demonstrates this. All you need to do is install and run the CODESYS Simulation Demonstrator.msi file.

Click the Browse button to search for the destination. It should appear as ISim_Target_xxx_xxx_xxx_xxx as you can see below. The following image also shows the use of the Simulation Interface object and the Simulation Demonstrator. The value Application_PLC_PRG_byOut was written by the publisher and the value Application_PLC_PRG_byIn was subscribed to by the simulation demonstrator via OPC UA PubSub.

_simitf_simtarget_simdemonstrator.png