TwinCAT PLC control of digital twin

Information on the digital twins, including downloads of the latest versions can be found in Digital twins. To use your controller on the digital twin, follow the steps below from Generating and importing PLC code and Activating PLC code.

Generating and importing PLC code

  1. Generate an XML-based PLC project from Eclipse, by executing the 3-plc-gen.tooldef script. The fastest way to do this, is to select the file in the Eclipse Project Explorer on the left and press F10.

  2. Start TwinCAT on your computer: Start menu > Beckhoff > TwinCAT XAE (VS 2013) or TwinCAT XAE Shell.

  3. Click: File -> Open -> Project/Solution.

    • Open the template plc-dt.sln, which can be downloaded from section TwinCAT template. This may take around a minute to load. You can watch progress in the purple bar at the bottom of your window.

    ../_images/open-project-twincat.gif
  4. Navigate to PLC -> Untitled1 -> Untitled 1 Project in the Solution Explorer.

    • Right-click on the Untitled 1 Project folder and click on ImportPLCopenXML….

    • Find the generated XML file plc.xml from step 1 to import. It is located in your group repository folder. Click Open to import.

    • In the next window, click OK. When doing this for the first time, a window opens that warns you that you are about to import files that already exist in the project. Select: Replace the existing object. Do the same for all subsequent conflicts. and click OK.

    ../_images/import-xml.gif

Activating PLC code

If you successfully followed the eight steps above, you may start your PLC-controlled digital twin. The next steps explain how you do it.

  1. Activate the configuration, click on img-activate-cfg button.

    • An Activate Configuration-window pops up. Click OK.

      After activating, you might get one of the two following messages (a or b). Note: Not all PC’s give this warning.

      a) Setting TwinCAT in Run Mode with Virtual Box running might fail. Click Continue and proceed to step 4.

      ../_images/warning-virtual-box.png

      b) Intel-VTx is not supported or not enabled in bios. This could mean two things: You forgot to enable Virtualization Technology as described in Initialization, or your computer does not support VT-x. If the latter case, follow the instruction on this page to isolate one of your processor cores. You can not continue with this guide before you did the steps that are described over there.

      ../_images/bios-vtx.png
    • Once every week you are asked to generate a trial runtime license. Click Yes and type the 5 characters in the box before clicking OK.

    • A dialog pops up with the message Restart TwinCAT System in Run Mode. Click OK.

      Sometimes TwinCAT shows an File Modification Detected or Conflicting File Modification Detected message after restarting in Run Mode. Whenever this happens, choose Ignore All.
      ../_images/IgnoreChangeRunMode.png
    ../_images/activating-plc.gif
  2. Login to the PLC by clicking on img-login.

    • A dialog pops up, click Yes to create and download an application on port 851.

  3. Start your digital twin program DT Workstation.exe. Where Workstation corresponds to your workstation. Wait until the program is fully loaded. Click Start to start the twin. You can download one of the twins from the download section.

  4. Start the PLC by clicking on img-start. Your digital twin should start its initialization sequence.

    ../_images/starting-plc.gif

Reset and restart the PLC with the same code

While your PLC is running (img-running), you can restart the code from the beginning without generating, importing a project or reloading your digital twin. This is the cold reset feature (img-reset-cold).

  • TwinCAT: Click on the reset cold button (img-reset-cold).

  • TwinCAT: Click YES in the next pop-up window.

  • Digital twin (optional): Pause menu (img-pause-menu) → Reload.

  • TwinCAT: Finally, click on start (img-start) to start the PLC code again.

An alternative option is reset origin (img-reset-origin). This option will reload the current application. However, when using this feature, you have to reload your digital twin program.

  • TwinCAT: Click on the reset origin button (img-reset-origin).

  • TwinCAT: Click YES in the next pop-up window.

  • TwinCAT: Login (img-login) (Port 851 download message).

  • Digital twin: Pause menu (img-pause-menu) → Reload.

  • TwinCAT: Finally, click on start (img-start) to start the PLC code again.

Reset and restart PLC after changes in your CIF model

  1. Stop the PLC:

    • Close the digital twin.

    • Stop the PLC by clicking the stop button img-stop in TwinCAT.

    • Logout from the PLC by clicking the logout button img-logout.

  2. Follow the steps from Generating and importing PLC code and the steps from Activating PLC code.

Stop the PLC when you are done

It is important to properly stop and logout from the PLC, otherwise the PLC will keep running in the background.

  1. Close the digital twin.

  2. Stop the PLC by clicking the stop button img-stop in TwinCAT.

  3. Logout from the PLC by clicking the logout button img-logout.

../_images/stopping-plc.gif

What to do when nothing seems to work

It might happen that your PLC is not running the same way as before, this could be caused by several things. Answer the following question(s) to find a possible cause:

  1. Does initialization start on the digital twin after starting the PLC img-start?

  2. Does initialization finish? e.g. sensor s_?initialized outputs TRUE and both indicator lights do not blink.

    • No → Try restarting the PLC.

    • Yes → The problem is caused by your designed controller. Carefully examine the state of actuators and sensors. The TwinCAT debug manual might help.

Note

Questions can be asked via the appropriate channels in Teams. Please use email only for private issues.