1、TwinCAT Total Windows Control and Automation TechnologyTwinCAT ADS2022-1-24Josef Papenfort2DefinitionExcursion: TwinCAT device concept a.) Identification of TwinCAT ADS devices b.) TwinCAT message router ADSa.) Introductionb.) Client-server relationshipc.) Access typesd.) Overview of methodsSet valu
2、es profiles2022-1-24Josef Papenfort3DefinitionADS = Automation Device Specification- modular ADS devices e.g. PLC (each run time system), NC,.- message exchange by ADS via the message routerADS (General)2022-1-24Josef Papenfort4ADS server unambiguously identifiable by:AdsAmsServerPortRouter unambigu
3、ously identifiable by:AdsAmsServerNetIDTwinCAT Device concept2022-1-24Josef Papenfort5- Every (TwinCAT) PC in the network can be uniquely identified by means of a TCP/IP address such as 172.1.2.16.- The AdsAmsServerNetID is an extension of the TCP/IP address, and identifies a message router, e.g. 17
4、2.1.2.16.1.1- The last two figures can be freely selected.Identification of ADS devices2022-1-24Josef Papenfort6The ADS servers of a message router are clearly identified by a number (- AdsAmsServerPort). The following AdsAmsServerPort numbers are already assigned:801,811,821,831: TwinCAT PLC server
5、, 1.-4. run-time system500: TwinCAT NC server100: TwinCAT loggerIdentification of ADS devices 2022-1-24Josef Papenfort7TwinCAT message router (I)Example:An ADS client sends an ADS message to an ADS server.The TwinCAT message router (transport layer 4) carries out: - acceptance of the request from th
6、e client- forwarding the message to an router if appropriate- provision of the messages to the ADS serverTwinCAT message router (I)2022-1-24Josef Papenfort8Existing message router:- On every TwinCAT PC- On every Embedded PC CX1000, CX1001- On every bus controller BX1000- On every bus controller (e.g
7、. BC3100, BC8100, ., BCxxxx)Possible communication paths:- Network (TCP/IP)A PLC run-time system sends data to another PLC on another TwinCAT PC in the network.- Fieldbus (Lightbus / Profibus)A PLC run-time system sends data to another PLC on a bus controller in the fieldbus.TwinCAT message router (
8、II)2022-1-24Josef Papenfort9The ADS interface permits:Standard:- communication with other ADS devices Client requests data or services, server answers automaticallySpecial solutions:- implementation of an ADS server (device) PLC : Extension of the existing ADS server functions of the PLC with the PL
9、C Library function blocks “Indication Response”Windows applications:TcSystem DLL(detailed information about ADS communication necessaryADS - Interface2022-1-24Josef Papenfort101.) Confirmed services2.) Unconfirmed servicesADS ClientADS ServerRequestIndicationConfirmationResponseClient-server relatio
10、nship2022-1-24Josef Papenfort11Example (PLC runtime 1) requests data from PLC (runtime2)ADS-ClientPLC IADS-Server PLC IIuses ADS FBProvides the dataRequestIndication(FB call)ConfirmationResponse(Busy at FB)Client server relationship between 2 PLC devices2022-1-24Josef Papenfort121.) By addressExampl
11、e:Read / write a total of 100 bytes starting from byte offset 20 of the input/output process image in the PLC server or of the flags area. (Often used in process visualisation)2.) By name“Example:Read / write the PLC variable temperature.Access types (I)2022-1-24Josef Papenfort13Synchronous. - Clien
12、t sends a request to server- Client waits until the result is existing- Synchronous to the program line“Access types, time flow (I)2022-1-24Josef Papenfort14Asynchronous- Client sends a query to the server- Client continues to work without waiting- Result of the server by callbackNotification- Clien
13、t registers itself at the server- Server serves the client autonomously by callback (until the client signs off from the server again)Access types, time flow (II)2022-1-24Josef Papenfort15Definition OCX:ActiveX-Control according to COM-(Component Object Model) SpecificationThe OCX contains:- general
14、 ADS services- extended ADS services, that simplify the process (e.g. synchronous communication)ADS OCX Introduction2022-1-24Josef Papenfort16AsynchronousADS OCX Introduction methods (I)SynchronousAdsSyncxxyyReq - per AdresseAdsSyncxxyyVarREQ -per NameAdsReadIntegerReqAdsReadLongReqAdsReadSingleReqA
15、dsReadDoubleReqAdsReadStringReqMethods for request(= Req)AdsReadIntegerConfAdsReadLongConfAdsReadSingleConfAdsReadDoubleConfAdsReadStringConfEvents at data updating (= Conf)AdsSyncReadBoolReqAdsSyncReadBoolVarReqAdsSyncReadIntegerReqAdsSyncReadIntegerVarReqAdsSyncReadLongReqAdsSyncReadLongVarReq2022
16、-1-24Josef Papenfort17ADS OCX Introduction methods (II)NotificationReadVarConnectExAdsReadConnectUpdateExAdsReadConnectUpdateExMethod for apply NotificationEvent after data updateMethod for sign off Notification AdsDisconnectExNotification. Connect?. EX?Notification is a term from the communication.
17、Connect is a term of the ADS Ocx method.EX: means Extended. It is the extended method of the old connect method. The difference is the easier handling. (- connectEx is recommended)2022-1-24Josef Papenfort18Notification Refresh Client (ADS Ocx) writes / reads data with own cycle.Client Cycle(e.g.) PL
18、C send only if variables changesServer on Change(e.g. PLC send with every cycle)Server Cycle2022-1-24Josef Papenfort19 Variable types Access Advantage Disadvantage Comment Synchro-nous All By address By name Easy handling in the Visual Basic Program The user must de-termine the event himself. (Disad
19、vantage when reading) If the answer pages are long, the VB program can slow down Local communication, fast networks, communication initiated at need Asynchro-nous All except BOOL Generally only by address. But (with more effort, i.e. using index group/index offset) also by name The Visual Basic Prog
20、ram does not wait for an answer, but continues to operate More administra-tive overhead in the Visual Basic program, since the answer requires reaction to an event. Slow communication (networks) large data packets Connect All By name By address Updating, takes place on the server (PLC) Unnecessarily
21、 high data traffic with many connect connections Specify sensible refresh times, clear connections that are not needed ADS OCX methods overview2022-1-24Josef Papenfort20Before communicating with an ADS device, the following properties of the communication partner must be specified once:- AdsAmsServe
22、rNetID (e.g. 172.1.2.16.1.1) and- AdsAmsServerPort (e.g. 801 PLC server, 1st run-time system)A separate ADS-OCX should be used for each ADS communication partner:e.g. ADS_OCX1 for PLC server 1st run-time systeme.g. ADS_OCX2 for NC servere.g. ADS_OCX3 for PLC server 2nd run-time systemFor communicati
23、on between one PC and several BC (9)000 Controllersone OCX and e.g. one additional I/O task can be used. The IO task “collects”all data from the BCs and the ADS OCX access to this area.Specifying the ADS communication partner2022-1-24Josef Papenfort21ADS-OCX Examples:ADS-OCX in Visual Basic projectI
24、Linking, simple data exchangeIIExamples: Synchronous and Connect“VBA IVBA with Graphworks synchronous data exchangeVBA IIVBA with Graphworks data exchange with connectVBA III VAB with excelADS OCX Examples2022-1-24Josef Papenfort22TwinCAT.ADS.Dll Examples:TwinCAT.ADS.Dll with VisualS and C#Ads.Dll C
25、# ILinking, simple data exchangeAds.Dll C# IIExamples: Synchronous and Connect“TwinCAT.Ads.Dll Examples2022-1-24Josef Papenfort235.1.b) Example Write a Variable Synchronously to the PLC The task: PLC Visual Basic In the PLC run-time 1 The local variable iVbToPlc1 in the MAIN program is to be overwri
26、tten by the Visual Basic application. An (integer) value is to be read from a text field in the Visual Basic application. This value is converted into an integer and saved in the global variables of the PLC project. Name: iVbToPlc1 This global variable is written into the PLC with a command button.
27、Example 12022-1-24Josef Papenfort24Local varVbToPlc1Only dummyinstructionExample 1PLC:Create a PLC project, create the main program and declare a local variable iVbToPlc12022-1-24Josef Papenfort25Project - componentsExample 1Visual Basic:Create Visual Basic, (standard.exe), link ADSOCX2022-1-24Josef
28、 Papenfort26TxtValueCmdWriteADSOCX1Example 1Visual Basic:Create form, place control elements2022-1-24Josef Papenfort27GeneralDeclarationsExample 1Visual Basic:Declare variable and handle for the variable2022-1-24Josef Papenfort28MarketingMarketingULILAKERSchulungSchulungsfolienADSOCXscreenshotsSet p
29、roperties(work local)Form Load Event(double click on the form)Set propertiesEnable exception , if method call incorrect, VB stops.Set propertiesPLC Runtime should be 1(=Port 801) Example 1Visual Basic:In FORMLOAD event set PROPERTIES for ADSOCX12022-1-24Josef Papenfort29Example I At faulty completio
30、n of a message, a message dialog is generated automatically.In the development environment of VB can be jumped to the program line along with the cause.By using the VB instructions On Error Goto / Resume an own error handling can be programmed.C#: Try and Catch2022-1-24Josef Papenfort30Method call w
31、ith evaluation(If an error occurs during execution (of the method), the return value does not equal 0.This can be used to trigger execution of an individual error handling process (here a message box).)Example 1Visual Basic:Other possibility for error evaluation2022-1-24Josef Papenfort31Example 1Vis
32、ual Basic:The handle is provided by the PLC and is known to the Visual Basic program. This handle can now be used to demand the variable from the PLC. The Click Event of the command button is selected as the trigger (event) for this action.First therefore read the text field, and assign this value t
33、o the variable.2022-1-24Josef Papenfort32AdsOcx1.AdsSyncWriteIntegerVarReq, what is the meaning of this name?As AdsOcx method is usedSynchronous writing(Synchronous is related to the processing of the Visual Basic program. Execution of the Visual Basic program only continues when execution of this m
34、ethod has been completed.)A value of type integerThis value is to be written via the name variable.Example 1Visual Basic:The handle is provided by the PLC and is known to the Visual Basic program. This handle can now be used to demand the variable from the PLC. The Click Event of the command button
35、is selected as the trigger (event) for this action.2022-1-24Josef Papenfort33This variable is to be written to the PLC.Example 1Visual Basic:In the click event of the command button.2022-1-24Josef Papenfort34Pay attention to Intelli Sense from Visual Basic (Studio)Handle which has previously been fe
36、tchedLength in bytes that will be required for transmission of the variable from the PLC to the Visual Basic application (integer 2 bytes)The VISUAL BASIC variable from which the value to be written is to be takenExample 1Visual Basic:In the click event of the command button.2022-1-24Josef Papenfort
37、35Test: Start PLC, save Visual Basic application and start. If everything is in order, the value in the text window of the Visual Basic program can be changed (-32768.+32767). After clicking the command button, the variable in the PLC program must have taken on this value.Example 1Visual Basic:Summa
38、ry: Click event2022-1-24Josef Papenfort36Synchronous access to bitlocated address, synchronous by name, by name and connect to several variables and write arrays synchronously.(Base project on training PC or disk)The controls are already placed on the form. A small editing possibility has been progr
39、ammed for the control Msflexgrid“. This example shows the pure using of the methods of ADS Ocx to access to the variables.The Enable Errorhandling“ is used to handle with errors. Example 2Visual Basic Example 22022-1-24Josef Papenfort37Example 2Visual Basic Example 2 Form2022-1-24Josef Papenfort38Fe
40、atures of ADS OCX by assignmentVisual Basic Example 2 FormExample 22022-1-24Josef Papenfort39Access to bitlocated PLC variableExample 2Visual Basic Example 2 Form2022-1-24Josef Papenfort40Access to bitlocated PLC variableExample 2Visual Basic Example 2 Form2022-1-24Josef Papenfort41Access to bitloca
41、ted PLC variableExample 2Visual Basic Example 2 Form2022-1-24Josef Papenfort42Access by name Example 2Visual Basic Example 2 Form2022-1-24Josef Papenfort43Access by nameVisual Basic Example 2 FormExample 22022-1-24Josef Papenfort44Access by name and connectStep 1: connectingExample 2Visual Basic Exa
42、mple 2 Form2022-1-24Josef Papenfort45Access by name and connectStep 2: analyse event from ADS OCX Example 2Visual Basic Example 2 Form2022-1-24Josef Papenfort46Access by name and connectStep 3: disconnectExample 2Visual Basic Example 2 Form2022-1-24Josef Papenfort47Access to an array synchronously b
43、y namefirst arrayVisual Basic Example 2 FormExample 22022-1-24Josef Papenfort48Access to an array synchronously by namesecond arrayVisual Basic Example 2 FormExample 22022-1-24Josef Papenfort49Required PLC variableExample 2Visual Basic Example 2 Form2022-1-24Josef Papenfort50Example AdsOcx with Gene
44、sis32 VBASynchronous data exchangeExample VBA I2022-1-24Josef Papenfort51Synchronized readPLC program changes Poti1“Synchronized writeExample VBA I: Synchronized write/read of PLC variables2022-1-24Josef Papenfort52Example VBA I: Graphworks322022-1-24Josef Papenfort53TextExample VBA I: Graphworks322
45、022-1-24Josef Papenfort54Process Point with located variableExample VBA I: Graphworks322022-1-24Josef Papenfort55MacrosGwxDemoReadByName_Main.DemoReadByNameExample VBA I: Graphworks322022-1-24Josef Papenfort56GwxWriteString_Main.WriteStringExample VBA I: Graphworks322022-1-24Josef Papenfort57Set mac
46、ro properties and get handle for Poti“ Example VBA I: Graphworks322022-1-24Josef Papenfort58Macro “read poti”(Poti lesen“)Example VBA I: Graphworks322022-1-24Josef Papenfort59Macro “Write product” (Produkt schreiben“)If a variable is not written frequently, producing handle, writing value and dissol
47、ving value can be run through in a sequence.Example VBA I: Graphworks322022-1-24Josef Papenfort60Delete macro handle for Poti“ by endExample VBA I: Graphworks322022-1-24Josef Papenfort61Example AdsOcx with Genesis32 VBA ConnectStart run-time- create handle Ads Ocx - analyse and display dataStop run-
48、time - delete handleExample VBA II2022-1-24Josef Papenfort62Example VBA II: PLC2022-1-24Josef Papenfort63Text“Object Name ConnectVar1Object Name ConnectVar1Object Name ConnectVar1Example VBA II: VB macro handle to connection2022-1-24Josef Papenfort64Example VBA II: Macro Connect2022-1-24Josef Papenfort65Example VBA II: analyse event ADS OCX 2022-1-24Josef Papenfort66Example VBA II: Disconnect at run-time stop2022-1-24Josef Papenfort67Example AdsOcx with Exel VBAData exchange with Connect and filling the list(In preperation)Example VBA III