Notes on the documentation

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.
It is essential that the following notes and explanations are followed when installing and commissioning these components.

The responsible staff must ensure that the application or use of the products described satisfy all the requirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly under development.
For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics.
In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning.
No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE® and XFC® are registered trademarks of and licensed by Beckhoff Automation GmbH.
Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners.

Patent Pending

The TwinCAT Technology is covered, including but not limited to the following patent applications and patents:
EP0851348, US6167425 with corresponding applications or registrations in various other countries.

Copyright

© Beckhoff Automation GmbH & Co. KG, Germany.
The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited.
Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.


OPC General

OPC Definition

OPC stands for "OLE for Process Control" and describes an initiative for standardisation of data exchange in automation.

Beckhoff is a member of the OPC Foundation. (More information about OPC may be obtained under www.opcfoundation.org)

OPC Interface

Formerly, applications such as operating and monitoring software were forced to use the differing access procedures of each controller manufacturer.
OPC is the specification of a universal software interface that is totally independent of the manufacturer. This opens up the possibility of gaining access in a unified manner to process data from any manufacturer.

OPC Server

An OPC server is a software component that offers a specified OPC interface to other applications.


Licensing

TwinCAT OPC can be used free of charge as an evaluation version without a registration key. Registration is necessary for general use. A licence for use of the software is obtained with this registration.

Registration instructions

During the installation

When installing TwinCAT OPC, the registration key (e.g. K123-4567-8901) can be entered into the appropriate field in the setup program. This removes the time restrictions placed on the evaluation version.

If no key is available at the time of installation, please enter "DEMO" as the key. The time-limited evaluation version of the TwinCAT OPC will be installed.

Subsequent registration of an evaluation version

Start the TwinCAT OPC server and select "Help->About TwinCAT OPC" from the main menu. By entering a valid registration number into the appropriate field, the time limit is removed from the evaluation version.


Overview

  • OPC Specification 1.0a and 2.0
  • Free choice of TwinCAT devices (ADS devices): PLC / IO / NC / CAM / ...
  • Access via TwinCAT PLC / TwinCAT I/O or bus controller to all the fieldbusses supported by TwinCAT (Lightbus / Profibus DP / Interbus-S / CANopen / DeviceNet / ...)
  • Access to TwinCAT variables by address / by name / by generic ADS IndexGroup and IndexOffset
  • Optimal access to data from the OPC server on TwinCAT variables (minimum cycle 10ms)
  • Simulation mode (sinus, ramp, random) for variables
    (i.e. testing an OPC client/server communication without access to physical I/O)
  • Simple configuration using file import, can also be manually performed or extended
  • Monitoring of variables in the OPC server

Features of the evaluation version

The evaluation version is a fully functional version with time limitations. Each time the OPC server is restarted, about 4 million accesses to the TwinCAT ADS devices (e.g. TwinCAT PLC / TwinCAT NC / TwinCAT IO...) are carried out. The OPC server then switches to its internal simulation mode. All the process values are then simulated, and there is no longer any access to the ADS devices.

The time limit in the evaluation version can be removed by purchasing a TwinCAT OPC software licence, and by the entry of a valid registration key.

Integration into the TwinCAT system

The OPC server is implemented as a "user mode application". This creates the connection to the TwinCAT system via ADS, and offers the specified OPC data access interface to OPC clients.

System requirements

  • Microsoft Windows NT 4 / Windows 2000
  • TwinCAT v2.6 (or higher)

Please use the latest Service Packs.

What is included

The installation version includes

  • TwinCAT OPC server
  • Documentation
  • OPC Test client (for local access to the OPC server)


Simulation mode

The TwinCAT OPC server can independently simulate process values, without direct access to, for example, the TwinCAT PLC.
It is not therefore necessary to have installed TwinCAT in order to carry out a test between an OPC client and the TwinCAT OPC server.

Activate simulation mode

Activate the "Simulate I/O" option in the "Device properties" dialogue.
All the tags that are arranged under this device are now simulated by the OPC server.

Select the tag simulation mode

In the "Tag properties" dialogue it is possible to choose one of the simulation modes - "sine", "ramp", "random" or "none" - for each individual tag.
The default setting is "none".

Save configuration

Save this configuration using "File"->"Save" or "File"->"Save as…". The OPC server will then use this configuration the next time it starts.


Overview

An OPC server represents a standardised interface for the management of process data. The process data available in the TwinCAT system must therefore be known to the OPC server, or must be made known to it at the time of configuration.
In order to represent what is known as the hierarchical process space clearly, it is divided into "devices", "groups" and "tags". The OPC client can browse through this representation and use it for the server's actual configuration. The TwinCAT OPC server supports the optional browser OPC interface.

Note:
This hierarchical display is not to be confused with the configuration of the OPC server that exists at run-time. The run-time configuration of the OPC server, i.e. the creation of groups, specification of the refresh time, the insertion of tags etc. is performed dynamically by the OPC client.

Device Definition

A device represents a TwinCAT ADS device (e.g. a PLC run-time system) that is uniquely identified by the <AdsAmsServerNetID> and the <AdsAmsPortID>.
Further information about the concept of devices in TwinCAT can be found in the general TwinCAT ADS documentation.

Group Definition

A device can contain any desired number of "groups", and thus functions as a container for groups.
The purpose of groups is to collect tags, or other lower-level groups, together using clear and meaningful names.

Tag Definition

A tag is the lowest level in hierarchical process space, and represents a link to a process variable. This is a readable and/or writable data item, e.g. "boiler set temperature".
One or more tags are assigned to a group.

Configuration

  • Receiving data from the TwinCAT PLC: Configuration by variable import from TwinCAT PLC control
  • Manual configuration: Alternative or additional possibility of manual configuration


Receiving data from the TwinCAT PLC

General

Manual configuration of the OPC server needs more and more time as the number of data points rises. This is made easier if data is imported from the TwinCAT PLC. A variables export file is first created in the IEC1131 programming environment, and this can then be imported into the OPC server. A detailed explanation of these steps is explained below.

1st step: Export from the TwinCAT PLC

TwinCAT 2.6:

In the TwinCAT PLC programming environment, select "Project"->"Export", and use the mouse to select the areas that you want to export (e.g. POUs and global variables). The variables can then be saved under a name *.EXP of your choice.

TwinCAT 2.7:

As an alternative TwinCAT 2.7 allows to create a symbolfile:

In the TwinCAT PLC programming environment, select "Project"->"Option"->"Symbolconfiguration". Activate "Create Symbol", and use the mouse to select under "Configure Symbolfile..." the areas that you want to export (e.g. POUs and global variables).

After compiling the PLC-project the new symbolfile "<yourProjectName>.sym" will be in the same folder as your plc-project.

REMARK:

  • Each compiling of the PLC-prject will automatically update the symbolfile.
  • The OPC-Server imports structure and array-elements out of *.SYM files.

2nd step: Import into the TwinCAT OPC server

The data to be imported is assigned to a device. (If no device has yet been created in the OPC server, a TwinCAT ADS device must first be generated by means of "Insert"->"New Device".)
Now use the mouse to select a device that will receive the PLC variables. Then select "File"->"Import EXP…", and choose the TwinCAT PLC export or the TwinCAT PLC Symbol file.

3rd step: Save configuration

Save the data that have been obtained in this way as an OPC server configuration. To do this, select "File"->"Save as…". The OPC server will retain this process space configuration when it is started again in the future.


Manual configuration

Insert device

Select "Insert"->"New device…" in order to insert another ADS device into the OPC server.

Device settings

Name:

Any name can be given to the device. (It should not, however, contain any spaces, since some OPC clients will then fail to perform tag browsing in the server.)

Simulate I/O:

Further information about the "Simulate I/O" option may be found in the section on the "Simulation mode ".

Device type / AMS address:

A connection to the AMS port of the selected target system is established.

ADS port:

Select an ADS device as the communication partner, e.g. "801" for the first PLC run-time system. In addition to the listed suggestions, any other AMS port number may be entered.

AMS port | Description
301 | TwinCAT-I/O Task
500 | TwinCAT NC
800 | BusController
801 | TwinCAT-PLC RunTime 1
811 | TwinCAT-PLC RunTime 2
831 | TwinCAT-PLC RunTime 3
841 | TwinCAT-PLC RunTime 4

The insertion causes the new device to be integrated into the tree representation.

If the settings for a device are to be modified at a later stage, select the device using the mouse, then select "Properties..." from the popup menu.
(As an alternative it is also possible to go from the main menu, via "Edit"->"Properties", into the "Device properties" dialogue.)

Add group

First select the device in which you would like to create a group. Select "New group..." from the popup menu.
(Or alternatively select "Insert"->"New group" from the main menu.)

Once you have given the group a name of your choice (e.g. "Machine_Config"), the new group is integrated into the tree representation.

If the name of a group is to be modified at a later stage, double-click with the mouse on the group entry in the tree representation.

Insert tag

First select the group in which you would like to create a tag. Select "New tag..." from the popup menu.
(Or alternatively select "Insert"->"New tag" from the main menu.)

Tag settings

Name:

Enter a name of your choice (e.g. "Temperature") for this tag.

Description:

You can, optionally provide a description for this process point.

Access type:

Access by address: (Physical Inputs) - %I
Access by address: (Physical Outputs) - %Q
Access by address: (memory Range) - %M

The OPC server's access to the variable is made, by address, to the process images. (e.g. for PLC, bus controller)
Optimisation: Device access optimisation is implemented internally through the generation of blocks.

Access by name

Access is made via the variable names.
Optimisation: Can not be implemented, there is a separate access each time to the ADS device.

Access by generic ADS IndexGroup / IndexOffset

Access is by means of the IndexGroup / IndexOffset.
Optimisation: Can not be implemented, there is a separate access each time to the ADS device.

Data type:

Specification of the data type

Length in bytes:

The byte length depends on the selected data type, and can only be specified in advance if the chosen type is "STRING".

R/W rights:

Specifies the access rights (read only / writing and reading).
The default setting is for writing and reading rights to be given.

Simulation signal:

Selection of the simulation mode (sine, ramp, random, none) for this process variable. The setting is only of any significance when the simulation mode is active. The default setting is "none".

Access by address:

Byte offset in the selected process region (input / output / flags)
Bit offset (only possible if the data type is BOOL)

Access by name:

The name of a TwinCAT variable is composed (in the PLC) from the POU name and the PLC variable that is to be addressed. (E.g. for the function 'Func1', the variable 'TempVar1' results in "Func1.TempVar1"). When accessing global variables (in the PLC) there is no POU name, which means that a "." (full stop) must be prefixed to it.
Upper and lower case letters are not distinguished.

Note for PLC:
Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. (See the PLC Control manual)

Note for NC:
Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue for the axis under 'General'. The "Create symbols" box must be checked. (See System Manager manual.)

Access by ADS (generic IndexGroup / IndexOffset):

A generic access to ADS devices is made by supplying the "IndexGroup" and "IndexOffset" parameters. Entry can take the form of a decimal or hex number.
Valid parameters may be found in the relevant ADS device documentation.


Network via client protocol

Visualisation systems sometimes offer their own protocol to bridge the network. An OPC client from the visualisation system supplier is also installed on the TwinCAT controller PC for this purpose.

The data flow proceeds as follows:

Performance advantage

The primary advantage of this configuration is that considerably less loading is placed on the network, since only the process values that have altered are exchanged there: the OPC server checks the whole process cyclically, but only passes the changes in the process on to the OPC client.


Network via TwinCAT ADS

The TwinCAT OPC server performs the communication with the TwinCAT components (PLC run-time systems, bus terminal controllers etc.) via TwinCAT ADS. Since these services are also available in the network, the TwinCAT OPC server can also communicate with TwinCAT components that exist in the network.

You will find the settings needed for ADS communication over a network in the ADS Reference.

Settings in the OPC server

An ADS communication partner is always specified by two parameters: These are what is known as the "AdsAmsNetId" (e.g. 1.2.3.4.5.6) and the "PortId" (e.g. 801 for the first PLC run-time system).

If ADS is to be used to exchange data with, for example, the first PLC run-time system on another PC, then the AdsAmsNetId of the target PC, and "801" as the PortId, must be entered in the OPC server under "Device settings".

Note

If possible, the option of using the "Network via client" protocol should be selected for performance reasons.


Network via DCOM

If you wish (or need) to allow data exchange between an OPC client and the TwinCAT OPC server over a network via DCOM, this DCOM access type must be configured beforehand.

The data flow is then as follows:

The following steps describe the necessary settings for the PC on which the TwinCAT OPC server is installed.
(Use step 1 for the PC on which the OPC client is installed.)

Requirement

It is assumed that all the PCs which are to participate via DCOM in an OPC client/server connection are already set up for network operation (i.e. they have configured network cards running the TCP/IP protocol)

Step 1

Via "Start" -> "Execute…", start "DCOMcnfg", and select the "Default settings" dialogue

  • Activate "Enable Distributed COM on this computer"
  • Select "None" for the "Default Authentication Level"
  • Select "Anonymous" for the "Default Impersonation Level"

Step 2

Select the "Applications" dialogue, and then the entry "TwinCAT OPC" from the list. With a double click, or via "Settings", you reach a further dialogue.

Step 3

Select the "Location" dialogue, and activate "Run application on this computer" there

Step 4

Select the "Security" dialogue

  • Activate "Use custom access permissions", and select "All".
  • Activate "Use custom configuration permissions", and select "Full control" access for "All".
  • Activate "Use custom launch permissions", and select "All".


Frequently Asked Questions

FAQ 001: The process values of variables are displayed as question marks when monitoring

FAQ 002: List of fieldbusses supported by the OPC server

FAQ 003: Test communication between OPC client and TwinCAT OPC server

FAQ 004: Implementation of an OPC client / access from Microsoft Office to the OPC server

FAQ 005: Further sources of information about OPC

FAQ 006: OPC client does not get any variable when browsing the OPC server's namespace

FAQ 007: Data exchange between OPC servers

Question 1:

Monitoring can be used in the OPC server to observe the current process value of OPC tags. However, in some cases only question marks appear instead of process values. What does this mean?

A: Those process values that are shown with question marks are not currently being requested by an OPC client. In such a case the OPC server does not communicate with the target device (e.g. the PLC run-time system), and can not therefore display a valid process value.

Question 2:

Which fieldbus systems can the TwinCAT OPC server access?

A: The OPC server exchanges data with, for instance, variables on the PLC run-time systems in the TwinCAT PLC, TwinCAT I/O, TwinCAT NC etc. or in BCxxxx bus controllers. These variables are mapped onto the various fieldbus I/O points with the aid of the TwinCAT System Manager. All the fieldbus systems that are supported by the System Manager can thus be reached via the TwinCAT OPC.

Question 3:

How is it possible to test the data exchange between the TwinCAT OPC server and a third party OPC client?

A: Installing the evaluation version of the TwinCAT OPC, which is free of charge, is sufficient for a test. This allows 4 million data accesses by the OPC server to the PLC each time it is started, and then switches into the OPC server’s simulation mode. From this point on, there is no access to the physical I/O, although the variables can be independently generated by the OPC server in various simulation modes (ramp / random / sine / none). When the OPC server is started again, another 4 million accesses can be made.

Test program:

A PLC test program (including a corresponding OPC server configuration file) is supplied when the OPC server is installed, and this permits a thorough test of the data types and the performance. In addition to about 2500 BOOL variables, 2 variables of each of many other data types (byte, signed integer, unsigned integer, signed long, unsigned long, real, double, string ) are defined. All the variables change their values cyclically.

In addition to checking data types and performance, optional interfaces such as the tag browser can be tested.

Question 4:

How is an OPC client implemented? Is it possible to access the OPC server from a Microsoft Office application (e.g. Access / Excel etc.)?

A: A number of firms offer training and toolkits for OPC server/client development. Beckhoff do not offer a toolkit. Using VBA programming it is possible with the aid of the "opcda.dll" to access the OPC server via the automation interface from, for example, Office applications.

Question 5:

Where can more information about OPC be obtained?

A: A number of firms offer seminars related to the topic of OPC. In addition to the OPC Foundation at http://www.opcfoundation.org/, the "OPC Programmers' Connection" at http://www.opc.dial.pipex.com/index.shtml offers more information such as documentation, demonstration source code, etc..

Question 6:

Why does the OPC client not obtain any data when browsing the ”namespace” of the OPC server?

A: Check whether the OPC server has been configured: If the OPC server starts without a configuration, then configure it. The OPC server starts with the last saved configuration.

If, however, the OPC server has been configured, the cause for the failure to browse can lie with an incompatibility of the OPC server and the client: older OPC clients only support "flat browsing", whereas the TwinCAT OPC server only supports the (standard) "hierarchical browsing".

Question 7:

How does the exchange of data between two (or more) OPC servers proceed?

A: Communication is exclusively between an OPC client and an OPC server, so that direct exchange of data between OPC servers is not possible. The only way around this is an OPC client that manages the flow of data between the OPC servers (a bridge function).


VB OPC-Demo

TwinCAT OPC Server: OPC with VB

Demo VB as OPC-Client

Common

Demo contains following files:

  • PLC Projectfile: opctest.pro
  • PLC exportfile: opctest.sym
  • VB demo: simple.frm and simple.vbp

-> Extract demofiles

Cookbook:

1.) Please start TwinCAT PLC-Control and load project opctest.pro into first PLC-runtime-system.

2.) Start TwinCAT-OPC-Server and and load opctest.tcf. Sace it again to be sure that server starts every time with this configuration.

3.)Load the VB project. Be sure that AUTODA.DLL (OPC-wrapper for automation-interface) is linked to your project under "Project->references"


OPC with LabVIEW

TwinCAT OPC Server: OPC with LabVIEW

Overview

LabVIEW

The LabVIEW graphical programming system from National Instruments supports the creation of applications without the need to write large amounts of program text. Programming is achieved through the selection, insertion and linking of graphical symbols into what are known as block diagrams, using a mouse. LabVIEW programs are called virtual instruments, or VI for short.

More extensive information on use and programming can be found in the LabVIEW manuals.

LabVIEW-VI’s as OPC-Clients

LabVIEW VI’s (since version 5.1) could be run as OPC-Clients, in order to communicate with an OPC-Server. This will be achieved only through a DataSocket-layer, thus the whole access, that means reading and writing of an OPC-Server, goes over these DataSockets-nodes; which can be easily found in the function palette under Communication/DataSocket and integrated into the block diagram of your VI.


LabVIEW OPC-Example

TwinCAT OPC Server: OPC with LabVIEW

Example-VI as OPC-Client

General

The following Example-VI LvOpcClient can be called and run immediatley without any special preparations. As soon as the VI is running, e.g. hit ‘Ctrl+r’, the user is asked for selecting two OPC-Items through a dialog with a tree-control; select one item for reading and one for writing.

In the present example the type of the selected OPC-Item the VI has to read is BYTE, that one to write of type BOOL. It is easy to replace the data types, by changing the type of the Indicator ‘Item ID Wert’ and the Control ‘Item ID neuen Wert geben’ to the desired types.

LabVIEW Datatype | TwinCAT PLC Datatype
Byte | SINT
Word | INT
Long | DINT
uByte | USINT
uWord | UINT
uLong | UDINT
SglPrec | REAL
Boolean | BOOL

When the OPC-Items are selected, the VI starts immediately to read the OPC-Item. The write-command will be triggered when you press the button ‘Wert schreiben’.

For further information how to configure the TwinCAT OPC-Server look up under Configuration.

The Front Panel

The Block Diagram