Connecting Beckhoff PLC with

Please note, that this Interface is only available in Professional


TwinCAT is the programming framework for Beckhoff PLCs. The TwinCAT interfaces uses ADS as communication framework to Beckhoff PLCs. The Bechoff PLCs can be virtual ones like the one delivered with the TwinCAT programming environment (which can be downloaded for free here or it could be a real PLC connected over the network with your PC.

The TwinCAT programming environment is enabling, just for development purposes, for free 7 day trial licenses for the TwinCAT PLC runtime. The virtual PLC can also act as a OPCUA server and it can be also used with the OPCUA interface. But we recommend to use directly the TwinCAT Interface if you just want to communicate with Bechoff PLCs because this interface is faster and creates less overhead than the OPCUA interface.

Prerequisites for TwinCAT ADS Communication

To establish TwinCAT ADS communication, you must have either a complete TwinCAT3 environment, which includes a virtual PLC, programming environment, and ADS router, installed on your PC, or you can opt to install just the TwinCAT ADS component (TC1000 TwinCAT 3 ADS). The necessary software is available for download from the official website.

Interface configuration

The TwinCAT interface is added to the Scene by selecting Tools > realvirtual > Add Component > Interface > TwinCAT or by adding the script TwinCATADSinterface to an empty GameObject.

You will get an inspector window like this:

For accessing the virtual or the hardware Beckhoff PLC you need to configure the NetID-Adress under Net Id and the Port number. The standard settings of the interface are for a local installed TwinCAT3 development environment with a local virtual PLC. For TwinCAT2 the Port number must be changed. For more information about the configuration of NetIDs and Ports please refer to the Bechoff documentation.

Importing signals

With Import signals all signals of the current TwinCAT project are imported.

Please make sure that NetID and PortID are configured and that the TwinCAT configuration is activated. Otherwise an error will appear if you try to import the signals. The icon of TwinCAT in the Windows Taskbar should now be green.

After importing the signals you get all signals as Gameobjects in your scene:

RegEx for Signal import

For limiting the number of signals you can define with RegEx (see special filters. In the simplest case a Regex is a part of a string which can be found in the Symbol name.

RegEx Import Signals For limiting the number of imported signals another RegEx can be used. In RegEx Import Signals one ore multiple RegEx as part of the signal names can be defined. If the list is empty everything is imported. If the list has one or multiple RegEx are defined only signals which are matching one of the RegEx are imported. For example be defining this RegEx

only signals which are named IO…. are imported like IO.TestInputBool,IO.TestOutputBool and so on.

RegEx Skip Signals If you give here one or multiple strings all signals which are matching one of the strings will not be imported.

RegEx Symbol is PLC Input If the imported signals are defined in the TwinCAT project as an Input or Output, the corresponding signal type will be attached to the Signal. For global TwinCAT variables, which are not assigned an input or output area, this is not possible, because it is not defined if the signal should be a PLC output or input. If it is not defined, the standard setting will import everything as input. You can change it manually by for example replacing the PLCOutputBool script against a PLCInputBool script. If you give here one or multiple strings all signals which are matching one of the strings will be imported as input. This is only necessary for global variables where it can’t be detected, if they are input our output.

Sub-folders when importing signals

TwinCAT is organizing variable in an object oriented approach. The signal symbol names are usually [object].[name]. You If the option Create sub folders is selected for each [object] one additional hierarchy in the Signal hierarchy is created.

Interface communication modes

The TwinCAT interface provides 3 different operation modes. Dependent on that mode, all signals are exchanged in a cyclic manner or signals are exchanged based on change events. You should select the mode which fits best your application and performance needs.

CyclicSumCommand This is the standard option and is the best performing mode with a lot of fast changing signals. The TwinCAT interface is operating in this case in Multithreaded mode and the thread status is displayed in the inspector. In this mode all signals are exchanged with one ADS command for reading and one ADS command for writing in each Thread cycle. For example about 700 input and output signals can be exchanged in a cycle of about 30ms. With MinCommCycleMS define a minimal cycle time and if you communication is faster the parallel thread is waiting for the next cycle. The communication thread is running independently from the main Unity thread and the signal data exchange will not slow down your simulation.

Cyclic The AdsNotification event is fired cyclically. The Notification will be registered on the ADS Server side for a cyclical trigger (dependent on time parameter) and is bound to the ‘default’ task of the addressed target. In case of the PLC target (e.g. Port 851) the default task is the first configured task. Each time the ‘default’ task has finished its cycle the real-time system will check for the expired cycle time and sends the AdsNotification message on expiry. Please be aware, that server side ‘Change’ notifications stress the real-time system and should be handled with care.

OnChange The Notification will be registered on the ADS Server side for an on-change and optional cyclical trigger (dependent on parameters) and is bound to the ‘default’ task of the addressed target. In case of the PLC target (e.g. Port 851) the default task is the first configured task. Each time this task has finished its cycle the realtime system will check for the changed value and an optional expired cycle time and sends the

Please note that Cyclic and OnChange can stress with a lot of fast changing signals the communication a lot and due to the many events the Unity and PLC performance can decrease dramatically. Please use this option only if the speed of signal changes and the number of changed signals is limited.

© 2022 in2Sight GmbH - All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including printing, saving, photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

Last updated