Receiving data from the TwinCAT PLC 2.8 and higher
1st Step TwinCAT PLC
TwinCAT 2.8 (or higher):
With TwinCAT 2.8 or higher an TwinCAT OPC-Server 4.1.0.79 (or higher) the OPC-configuration has become very easy and has to be done just once.
After the PLC project has been compiled, there is always a file in the PLC project directory with the name structured as "<project name>.tpy".
- The *.tpy file is automatically replaced each time the PLC project is compiled.
In the PLC Control navigate to "Projects.. Options... TwinCAT" and select "Download symbol description". With each compile the <projectname>.typ file is now transported to target system and stored as e.g. "\TwinCAT\Boot\CurrentPLC_1.tpy" for first PLC-runtime system, or "\TwinCAT\Boot\CurrentPLC_2.tpy" for second PLC-runtime system etc. - Which PLC variable is available via OPC ?
With adding simple information done by the declaration of the PLC-variable you can mark a PLC variable to be known by the OPC-Server. This helps to reduce the OPC-namespace. - The OPC-DA Server will automatically connect to PLC runtime and provide PLC-variables which are marked for OPC-DA within the PLC-Control.
- Mark the PLC-variables with a comment to enable them beeing accessed by OPC-DA Server.
Extra comments in PLC-IEC1131 Editor will modify the configuration of opc-server:
Sample1:
PLC variable "bMemAlarm"1 will not be available via OPC-DA-Server
Sample2:
Two instances fbTest and fbTest2 of FB_BLOCK1.
Due to fbTest is marked with (OPC:1), all members of FB_BLOCK1 are available via OPC-DA
Instance fbTest2 is not marked, but three member variables (ni1 / no1/ nx1) are marked to be available in all instances - the OPC-DA clent will browse only that three variables.- To configure a PLC variable for readonly-access, the comment needs to be set with OPC_PROP[0005], as shown above for the variable iReadOnly. Please make sure to write this property exactly as shown above!
2nd step: Configuration of TwinCAT OPC Server - to be done just once
Start the TwinCAT-OPC-Configurator "Start - All Programs - TwinCAT System - TwinCAT OPC - TwinCAT OPC Configurator"
Select "I/O Devices" with right click and then menu "New".
For "Name" please enter a name for this alarm definition.
This name has to be OPC conform, no special characters allowed.
Sample: The TwinCAT-PLC runtime-system 1 has a PLC variable "temperatur".
Definition of devicename with "Plc1" will publish the PLC variable via OPC as "Plc1tTemperatur" later for OPC-Clients.
After applying with "OK" you see the next dialog with settings of the new device "Plc1"
For option "AutoCfg" select option "8 Link and filter to generic TwinCAT symbol file"
For option "AutoCfgFile" click to "Search-buton" and navigate to e.g. "C:\TwinCAT\Boot\CurrentPLC_1.tpy"
If you work on a small PLC project and all PLC variables should be available for OPC you can select option "AutoCfg" "7 Link to generic TwinCAT symbol file"
In this case all PLC variables are imported, the filter comment in the PLC Control is ignored.
Following settings have to be checked:
Requirements
Type | Req./Opt. | Description |
---|---|---|
Name | Req | Name for device like "PLC1". OPC-Client browse this name |
Description | Optional |
|
AutoCfg | Optional | 1 : Include sym-file of TwinCAT-PLC defined under <AutoCfgSymFile> 8 : Include tpy-file of TwinCAT28-project defined under <AutoCfgSymFile>, but import only symbols with symbol-property "OPC=1" |
AutoCfgSymFile | Optional | full path and name of symbol-file to be included like C:\Test\demo.sym" or " \\User1\Test\demo.sym" or "C:\TwinCAT\Boot\CurrentPLC_1.tpy" |
|
|
|
AdsPort | Req | Number of ADS-PortID, like 821 for first PLC-runtime system 800 for PLC-runtime system on BC |
AdsNetId | Optional | specific ADS-NetId, like "174.12.15.45.1.1" If not specified or like "0.0.0.0.0.0", the OPC-Server will always communicate to AdsNetId of local ADS-router. |
AdsTimeout | Optional | ADS timeout in ms for this ADS device. If ADS device will not replay within this time, the OPC-Server will set the requested variables to "BAD QUALITY" |
AdsTimeSuspend | Optional | ADS suspend time in ms for this ADS device, if the ads communication fails. If an ADS device is running, it does not make sense to communicate with high frequence to that device. In case of ads-communication trouble the OPC-Server will wait till next ads-request to that device. |
|
|
|
Disable | Optional | Disables this device. OPC-Server will ignore this device. |
See detailed description in appendix.
3 rd step : Check and save configuration
Save the configuration unter current name or select menu "File - Save As..." to insert a new name.
The OPC-Configurator will save the XML based file.
After saving the OPC-configurationfile we get the option to activate this configuration to be the configuration for next startup of OPC-Server.
After selecting "Yes" this current configuration will be the start-configuration of the opc-server. With next start of OPC-Server this new configuration will be active.
If you activated a new OPC-configuration, but the OPC-Server still has old namespace and settings the reason is that the OPC-Server was not stopped and restarted. |