
4000通讯VBADS通讯.ppt
67页TwinCAT Total Windows Control and Automation TechnologyTwinCAT ADSDefinitionExcursion: TwinCAT device concept a.) Identification of TwinCAT ADS devices b.) TwinCAT message router ADSa.) Introductionb.) Client-server relationshipc.) Access typesd.) Overview of methodsSet values profiles9/9/20242Josef PapenfortDefinitionADS = Automation Device Specification- modular ADS devices e.g. PLC (each run time system), NC,...- message exchange by ADS via the message routerADS (General)9/9/20243Josef PapenfortADS server unambiguously identifiable by:AdsAmsServerPortRouter unambiguously identifiable by:AdsAmsServerNetIDTwinCAT Device concept9/9/20244Josef Papenfort- 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. "172.1.2.16.1.1"- The last two figures can be freely selected.Identification of ADS devices9/9/20245Josef PapenfortThe 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, 1.-4. run-time system500: TwinCAT NC server100: TwinCAT loggerIdentification of ADS devices 9/9/20246Josef PapenfortTwinCAT 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 the client- forwarding the message to an router if appropriate - provision of the messages to the ADS serverTwinCAT message router (I)9/9/20247Josef PapenfortExisting message router:- On every TwinCAT PC- On every Embedded PC CX1000, CX1001- On every bus controller BX1000- On every bus controller (e.g. 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 (II)9/9/20248Josef PapenfortThe 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 PLC Library function blocks “Indication Response”Windows applications:TcSystem DLL(detailed information about ADS communication necessaryADS - Interface9/9/20249Josef Papenfort1.) Confirmed services2.) Unconfirmed servicesADS ClientADS ServerRequestIndication ConfirmationResponse Client-server relationship9/9/202410Josef PapenfortExample (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 devices9/9/202411Josef Papenfort1.) "By address"Example: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)9/9/202412Josef PapenfortSynchronous. -> Client sends a request to server-> Client waits until the result is existing-> „Synchronous to the program line“Access types, time flow (I)9/9/202413Josef PapenfortAsynchronous-> Client sends a query to the server-> Client continues to work without waiting-> Result of the server by callbackNotification-> Client 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)9/9/202414Josef PapenfortDefinition OCX:ActiveX-Control according to COM-(Component Object Model) SpecificationThe OCX contains:- general ADS services- extended ADS services, that simplify the process (e.g. synchronous communication)ADS OCX Introduction9/9/202415Josef PapenfortAsynchronousADS OCX Introduction methods (I)SynchronousAdsSyncxxyyReq -> per AdresseAdsSyncxxyyVarREQ ->per NameAdsReadIntegerReqAdsReadLongReqAdsReadSingleReqAdsReadDoubleReqAdsReadStringReqMethods for request(= Req)AdsReadIntegerConfAdsReadLongConfAdsReadSingleConfAdsReadDoubleConfAdsReadStringConfEvents at data updating (= Conf)AdsSyncReadBoolReqAdsSyncReadBoolVarReqAdsSyncReadIntegerReqAdsSyncReadIntegerVarReqAdsSyncReadLongReqAdsSyncReadLongVarReq9/9/202416Josef PapenfortADS 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.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)9/9/202417Josef PapenfortNotification Refresh Client (ADS Ocx) writes / reads data with own cycle.Client Cycle(e.g.) PLC send only if variables changesServer on Change(e.g. PLC send with every cycle)Server Cycle9/9/202418Josef PapenfortADS OCX methods overview9/9/202419Josef PapenfortBefore communicating with an ADS device, the following properties of the communication partner must be specified once:- AdsAmsServerNetID (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 communication 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 partner9/9/202420Josef PapenfortADS-OCX Examples:ADS-OCX in Visual Basic projectILinking, 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 Examples9/9/202421Josef PapenfortTwinCAT.ADS.Dll Examples:TwinCAT.ADS.Dll with VisualS and C#Ads.Dll C# ILinking, simple data exchangeAds.Dll C# IIExamples: "Synchronous" and "Connect“TwinCAT.Ads.Dll Examples9/9/202422Josef Papenfort5.1.b) Example "Write a Variable Synchronously to the PLC"Example 19/9/202423Josef PapenfortLocal varVbToPlc1Only dummyinstructionExample 1PLC:Create a PLC project, create the main program and declare a local variable iVbToPlc19/9/202424Josef PapenfortProject -> componentsExample 1Visual Basic:Create Visual Basic, (standard.exe), link ADSOCX9/9/202425Josef PapenfortTxtValueCmdWriteADSOCX1Example 1Visual Basic:Create form, place control elements9/9/202426Josef PapenfortGeneralDeclarationsExample 1Visual Basic:Declare variable and handle for the variable9/9/202427Josef Papenfort\\Marketing\Marketing\ULILAKER\Schulung\Schulungsfolien\ADSOCX\screenshotsSet properties(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 ADSOCX19/9/202428Josef PapenfortExample I At faulty completion 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 Catch9/9/202429Josef PapenfortMethod call with 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 evaluation9/9/202430Josef PapenfortExample 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 is selected as the trigger (event) for this action.First therefore read the text field, and assign this value to the variable.9/9/202431Josef PapenfortAdsOcx1.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 method 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 is selected as the trigger (event) for this action.9/9/202432Josef PapenfortThis variable is to be written to the PLC.Example 1Visual Basic:In the click event of the command button.9/9/202433Josef PapenfortPay attention to Intelli Sense from Visual Basic (Studio)Handle which has previously been fetchedLength 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.9/9/202434Josef PapenfortTest: 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:Summary: Click event9/9/202435Josef PapenfortSynchronous 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 programmed 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 29/9/202436Josef PapenfortExample 2Visual Basic Example 2 Form9/9/202437Josef PapenfortFeatures of ADS OCX by assignmentVisual Basic Example 2 FormExample 29/9/202438Josef PapenfortAccess to bitlocated PLC variableExample 2Visual Basic Example 2 Form9/9/202439Josef PapenfortAccess to bitlocated PLC variableExample 2Visual Basic Example 2 Form9/9/202440Josef PapenfortAccess to bitlocated PLC variableExample 2Visual Basic Example 2 Form9/9/202441Josef PapenfortAccess by name Example 2Visual Basic Example 2 Form9/9/202442Josef PapenfortAccess by nameVisual Basic Example 2 FormExample 29/9/202443Josef PapenfortAccess by name and connectStep 1: connectingExample 2Visual Basic Example 2 Form9/9/202444Josef PapenfortAccess by name and connectStep 2: analyse event from ADS OCX Example 2Visual Basic Example 2 Form9/9/202445Josef PapenfortAccess by name and connectStep 3: disconnectExample 2Visual Basic Example 2 Form9/9/202446Josef PapenfortAccess to an array synchronously by namefirst arrayVisual Basic Example 2 FormExample 29/9/202447Josef PapenfortAccess to an array synchronously by namesecond arrayVisual Basic Example 2 FormExample 29/9/202448Josef PapenfortRequired PLC variableExample 2Visual Basic Example 2 Form9/9/202449Josef PapenfortExample AdsOcx with Genesis32 VBASynchronous data exchangeExample VBA I9/9/202450Josef PapenfortSynchronized readPLC program changes „Poti1“Synchronized writeExample VBA I: Synchronized write/read of PLC variables9/9/202451Josef PapenfortExample VBA I: Graphworks329/9/202452Josef PapenfortTextExample VBA I: Graphworks329/9/202453Josef PapenfortProcess Point with located variableExample VBA I: Graphworks329/9/202454Josef PapenfortMacrosGwxDemoReadByName_Main.DemoReadByNameExample VBA I: Graphworks329/9/202455Josef PapenfortGwxWriteString_Main.WriteStringExample VBA I: Graphworks329/9/202456Josef PapenfortSet macro properties and get handle for „Poti“ Example VBA I: Graphworks329/9/202457Josef PapenfortMacro “read poti”(„Poti lesen“)Example VBA I: Graphworks329/9/202458Josef PapenfortMacro “Write product” („Produkt schreiben“)If a variable is not written frequently, producing handle, writing value and dissolving value can be run through in a sequence.Example VBA I: Graphworks329/9/202459Josef PapenfortDelete macro handle for „Poti“ by endExample VBA I: Graphworks329/9/202460Josef PapenfortExample AdsOcx with Genesis32 VBA ConnectStart run-time-> create handle Ads Ocx -> analyse and display dataStop run-time -> delete handleExample VBA II9/9/202461Josef PapenfortExample VBA II: PLC9/9/202462Josef Papenfort„Text“Object Name ConnectVar1Object Name ConnectVar1Object Name ConnectVar1Example VBA II: VB macro handle to connection9/9/202463Josef PapenfortExample VBA II: Macro Connect9/9/202464Josef PapenfortExample VBA II: analyse event ADS OCX 9/9/202465Josef PapenfortExample VBA II: Disconnect at run-time stop9/9/202466Josef PapenfortExample AdsOcx with Exel VBAData exchange with Connect and filling the list(In preperation)Example VBA III9/9/202467Josef Papenfort。
