It is a free and open communication protocol developed by Beckhoff Automation. According to Beckhoff, the ADS (Automation Device Specification) is a transport layer within the TwinCAT system that was developed for data exchange between the different software modules, for instance, the communication between the NC and the PLC. This protocol enables communication with other tools from any point within the TwinCAT. ADS enables the communication between RealTime and UserMode.
If communication with other PCs or devices is required, the ADS protocol can use TCP/IP as a basis. Within a networked system, it is thus possible to reach all data from any point. In the TwinCAT system, the individual modules of the software (e.g. TwinCAT PLC, TwinCAT NC …) are considered as independent devices and the messages between these objects are exchanged through a consistent ADS interface by the “message router”. TwinCAT message routers exist on every TwinCAT PC. This allows all TwinCAT server and client programs to exchange commands and data.
In the below picture you can see the Structure of ADS Communication
Each TwinCAT system can be addressed by it‘sNetId. (AMS Net ID -> ADS Message SpecificationNet ID)
Each ADS device can be identified by a Port (for example port number 501 is NC and 851 is PLC runtime1)
Our goal is to read an internal variable of CX5010 (CX-20C382) controller from the TwinCAT system of a Laptop
What do we need to have/create?
- The route between TwinCAT systems
- The Transport layer
Creating/configuring route between TwinCAT systems
Add a static route to your neighbors (target) TC runtime(PLC) Only one side needs to create a route. It is automatically created on the other side.
Then, we need to check, On both sides, if the static route to the neighbor exists!
As it is shown in the below picture, we have the route on both TwinCAT systems.
The transport layer
The network range must match (Ports must be opened). As we have Windows CE in our CX controller and Windows 10 on the laptop the procedure is a bit different.
For CX5010 (with Windows CE); on the configuration tool/Firewall we can check/add the proper rules (UDP and TCP/IP) as a permitted transport type for windows firewall.
as you can see below, the right Rules are available in our CX controller.
And for the laptop (Windows 10) we need to check inbound and outbound rules in the advanced setting of windows firewall. We can check if there are proper rules otherwise we can create the new rules. in the below picture, we can see that there are two proper rules (TCP/IP and UDP) but we can always create them if they are not available.
The ADS Route info is stored in the TwinCAT system route table. C:\TwinCAT\3.1\Target\StaticRoutes.xml The ADS information of the CX controller are correctly assigned in Laptop TwinCAT system (see below picture)
We need to use ADS function blocks, from the PLCSystem.lib library, to have access into the Bus Coupler information directly from a PC. For reading/accessing a variable we can use ADSREAD function block.
As it is shown in the above picture, we need these data (inputs) to create proper access to a variable:
- The AMS Net ID (the TwinCAT system ID)
- Port number (the TwinCAT Device ID)
- Details about the variable (Variable name or variable exact address or defining specific Index Group/Offset)
- IndexGroup / IndexOffset
“Index-Group/Offset” Specification of the PLC services can be found here:
for example, as it is shown in the below picture, For accessing a variable by Address in the %MB range, you need to point at IndexGroup 16#4020, and IndexGroup 16#4040 is used for assigning Data range.
For our test, we use IndexGroup 16#4040, and here is the step by step procedure description.
As shown belo, For CX5010, we need to create a PLC program with one Integer variable (only declaration is required here)
After building the PLC project, on the PLC project instance, by selecting the Data Area tab. We need to find the corresponding PLC variable, the size and offset will be used/needed.
And on the other side (on Laptop) we need to create a PLC program with ADSREAD function block
As you can see in the above picture, the important input variables are filled as below
- NETID: 192.168.201.30.1.1, AmsNetId of CX5010 PLC
- PORT: 851, which is PLC’s Runtime system 1
- IDXGRP: 16#4040, as discussed before
- IDXOFFS: 520484, copied from the variable offset (CX5010)
- LEN: the length of the variable is requested with SIZEOF operator
- DESTADDR: the address of the variable is requested with ADR operator
- READ: The ADS command is triggered by a rising edge at this input and the target variable would be read at that certain moment.
And here is the final result:
The number of Calls/Transmissions of ADS communication is limited but the size of a message is almost unlimited. Therefore, to avoid overflow mailbox and making the system slow, the number of call should be controlled by “State Machine” To make sure you only service one ADS call in each state/PLC cycle. And also to check the BUSY flag on your ADS block before making a new call. If you only need to exchange data with just one TwinCAT device, then it is highly recommended to exchange one big structured type instead of many ADSREAD for different individual type variables.
In general, it is recommended by Beckhoff that the best practice is only to do ADSREAD and not ADSWRITE. If you want to change some kind of value in the other TwinCAT device, Present the new value on your own side and let the other side read your request and write it to the variable. Invent some kind of handshake. This way, if the other side makes changes to variables and memory size, you do not WRITE to a wrong offset by accident.