beckhoff TX1000 — 4.1 Sample Machine with Microsoft Expression Blend (C#)

Samples WPF 5. Editing the source code Now the creation of the source code in C# can be started. The required namespaces 'System.IO' and 'TwinCAT.Ads' are inserted into the top line of the source code. using System.IO; using TwinCAT.Ads; This is followed by the declarations. privateTcAdsClient tcClient; privateAdsStream dataStream; privateBinaryReader binReader; private int hEngine; private int hDeviceUp; private int hDeviceDown; private int hSteps; private int hCount; private int hSwitchNotify; private int hSwitchWrite; The first method is the 'Load' method. It is used to generate instances of different classes and create a link to port 801.

//-----------------------------------------------------// Wird als erstes beim Starten des Programms aufgerufen// Is activated first when the program is started//-------------------------------------- ---------------private void Load(object sender, EventArgs e) { try { // Eine neue Instanz der Klasse AdsStream erzeugen// Create an new instance of the AdsStream cl ass dataStream = new AdsStream(7); // Eine neue Instanz der Klasse BinaryReader erzeugen// Create a new instance of the BinaryRead er class binReader = new BinaryReader(dataStream); // Eine neue Instanz der Klasse TcAdsClient erzeugen// Create an new instance of the TcAdsClien t class tcClient = new TcAdsClient(); // Verbinden mit lokaler SPS - Laufzeit 1 - Port 801// Connecting to local PLC - Runtime 1 - Port 801 tcClient.Connect(801); TX1000 32 Version:

1.2