Home > Enterprise >  (reproduced) times the Beckhoff TWinCAT ADS PLC programming briefly
(reproduced) times the Beckhoff TWinCAT ADS PLC programming briefly

Time:09-19



(reproduced) times the Beckhoff TWinCAT ADS PLC programming description
Original: https://www.apps121.com/2018/07/30/beckhoff-twincat-ads-plc/

A, happy times TWinCAT ADS description
In the Beckhoff TwinCAT system, various software modules (such as TwinCAT PLC, TwinCAT NC, Windows applications, etc.) and hardware system CX, BX, BC series controller TwinCAT information contained in the router, so to be able to exchange data between different ADS equipment and information,

Second, TWinCat ADS equipment identifiers
Each TwinCAT ADS equipment have their own different AdsAmsNetId and AdsPort (port), AdsAmsNetId is an extension of the TCP/IP address, the default value is based on IP. 1.1, can also be modified,

ADS Client (ADS) Client application AdsPort is mutable, different ADS equipment AdsPort as shown in the figure below:


Three, TwinCat ADS communications (both synchronous and asynchronous)

Asynchronous (Asynchronous)
ADS of ADS to ADS server client request, at the same time the client to continue their work, ADS after the server processes the request, the response sent to the client in Call - back function way,
Advantages: not cause system congestion
Disadvantages: does not ensure every request returns a

Synchronously (Synchronous)
ADS of ADS to ADS server client request, the client program in the process of communication and until get ADS returned by the server response

Advantages: instantly returns the
Disadvantages: if the communication failures cause jams systems

Synchronously (Synchronous) communication is divided into two kinds, namely the read and write operations, to read and write operations were divided into two ways, namely and carried out in accordance with the address according to the variable name, speaking, reading and writing, speaking, reading and writing,

1. The way of the variable name
Each variable in the TwinCAT PLC program has a Handle (Handle), before the operation of variable, we must first get through relevant path variable Handle, and then to read and write operations, after the operation to release the Handle,

2. Address mode
The address of a variable in the TwinCAT PLC consists of two parts, namely GroupIndex and OffsetIndex GroupIndex as the variables in the types of registers as a constant; OffsetIndex as the variables in the register address offsets, as a variable,



For MX, IX, QX registers the offset is the unit of "a", rather than bytes, calculate the address need to pay attention to
2. Maximum offset 0 M register x0000ffff, and MX, I, IX, Q, QX maximum offset 0 XFFFFFFFF,
3. The above-mentioned three main for c + + language, after other senior language has encapsulated into a proprietary method, need not be called directly,

Four, according to the variable name and operated at variable address is
1. The way of the variable name
Advantages:
A, don't need to know the variable specific address;
B, can be omitted to calculate the address;
C, operation of process variables;
Disadvantages:
A, because must grasp the handle to put (10 ms), slow compared to address way communication
B, on the BC, BX series can't operate

2. Address mode
Advantages:
A, directly to the address, save to grasp the handle time, fast communication;
B, don't need to know the specific path variable;
C, can operate the BC, BX series controller
Disadvantages:
A, use should be considered in the different variable offset, error-prone,

Five, TwinCAT communication interface in a high-level language

? Open, simple, flexible and complete document



Six, TwinCAT communication component in a high-level language
For the convenience of a variety of computer high-level language use ADS communication and the environment, Beckhoff TwinCAT offer the following components:
? ADS the.net Component
For the.net platform, VB.NET, c #, etc.
? ADS - OCX (ActiveX COM controls)
Apply to Visual Basic, Visual c + +, Delphi, etc.
? ADS - DLL
Apply to Visual c + +, etc.
? ADS - Script - DLL
Apply to the VBScript, Jscript script, such as create the application of B/S architecture.
? JAVA DLL
Applicable to the JAVA language,
? "PlcSystem. Lib" PLC library
ADS equipment can according to this and other ADS as well as Windows communicate

Seven, TwinCAT communications high-level language component to get
ADS integrated in the TwinCAT software component library, install any version of the TwinCAT software contain ADS communication components, if the user wants to computer suitable ADS communication there is no installation TwinCAT software components can be installed in the Supplement TwinCAT_ADS_Communication_Library this for free products,

Eight, Qt c + + VS2015 project setup example
A, need to related files
Need to include the header file: TcAdsAPI. H and TcAdsDef. H
Need to include the.lib file: TcAdsDll Lib
Application directory needs to include the library files: TcAdsDll. DLL

B, set mode
We have to create a new directory under the project directory, named: ads_include [include file TcAdsAPI. H and TcAdsDef. H]
Join engineering method: engineering properties - & gt; C/C + + - & gt; Conventional adding ads_include additional include directories to
We have to create a new directory under the project directory, named: libs [include file TcAdsDll. Lib]
Join engineering method: engineering properties - & gt; The linker - & gt; Conventional libraries add libs directory to
Engineering properties - & gt; The linker - & gt; Enter additional dependencies added TcAdsDll. Lib can
At the same time need to put the TcAdsDll. DLL library placed in execution directory,

Nine, recommend Qt c + + software structure design [has been the transition practice]


Ten, other problems
1, pay attention to the byte alignment, as far as possible a unified use bytes 4 or 8 times, also can greatly improve the memory access
2, pay attention to the communication efficiency, try to use address access
3, pay attention to thread synchronization, keep main thread interface operation


Original: https://www.apps121.com/2018/07/30/beckhoff-twincat-ads-plc/

  • Related