
ADS
ADS stands for automation device specification. It was developed for data communication between different modules. Without this, we could have nightmares, if we write our own communication modules using TCP/IP that is lots of work. We just use the work done by somebody and focus on our task on hand. The ADS protocol runs on top of the TCP/IP or UDP/IP protocols. It allows the user within the Beckhoff system to use almost any connecting route to communicate with all the connected devices and to parameterize them. if you want to know more please follow the following pages.
https://www.hemelix.com/software/plc-to-pc-by-c-sharp/
https://www.hemelix.com/scada-hmi/twincat-hmi/beckhoff-pc-plc-communication-module-development/
https://infosys.beckhoff.com/english.php?content=../content/1033/cx8180_hw/5091854987.html&id=

Software interfaces
ADS-OCX
The ADS-OCX is an Active-X component. It offers a standard interface to, for instance, Visual Basic, Delphi, etc.
ADS-DLL
You can link the ADS-DLL (DLL: Dynamic Link Library) into your C program.
OPC
The OPC interface is a standardized interface for communication used in automation technology. Beckhoff offer an OPC server for this purpose.
Protocol
The ADS functions provide a method for accessing the Bus Coupler information directly from the PC. ADS function blocks can be used in TwinCAT for this. The function blocks are contained in the Tc2_System.lib library. It is also equally possible to call the ADS functions from AdsOCX, ADSDLL or OPC.
AMSNetID
The AMSNetID provides a reference to the device that is to be addressed. This is taken from the MAC address of the first Ethernet port (X001) and is printed on the side of the CX80xx. For the AMSNetID the bytes 3..6 plus “.1.1” are typically used.
Example:
MAC address 00-01-05-01-02-03
AMSNetID 5.1.2.3.1.1
Port number
The port number distinguishes sub-elements in the connected device.
Port 851: local process data PLC runtime 1
Index group
The index group distinguishes different data within a port.
Index offset
Indicates the offset, from which reading or writing the byte is to start.
Len
Gives the length of the data, in bytes, that is to be read or written.
TCP port number
The TCP port number for the ADS protocol is 48898 or 0xBF02.
Tips
Tips 01:
Windows data type and size are different in TwinCAT structured text. This causes problems, especially when we write data over ADS in C#. Here is an example, we have declared a variable in the Windows program as the following
int myWinInt = 200;
object rawValue = myWinInt ;
client.WriteAny(handle, rawValue); // This will throw an exception “parameter size not correct” if the variable in PLC is declared as INT type.
myPLCIntType : INT := 0; //Declared in PLC
Solution:
Make sure the data size in PLC is equal to or higher than the size of the Windows variable, the above case can be solved in the following way.
int myWinInt = 200; // 4 bytes in Windows
myPLCIntType : DINT := 0; // 4 bytes in PLC
OR
short myWinInt = 200; // 2 bytes in Windows
myPLCIntType : INT := 0; // 2 bytes in PLC