-// wird aufgerufen, wenn das Feld 'langsam' markiert wird// is activated when the 'slow' field is marked//-private void optSpeedSlow_Click(object sender, EventArgs e) -// wird aufgerufen, wenn das Feld 'schnell' markiert wird// is activated when the 'fast' field is marked//-private void optSpeedFast_Click(object sender, EventArgs e)
They are used to switch a virtual switch by writing a value to the PLC variable 'switch'. There are still two methods missing for setting the speed of the machine. Markieren des korrekten RadioButtons// Checking the correct RadioButtonif (binReader.ReadBoolean() = true) LblCount.Text = binReader.ReadUInt16().ToString() Įlse if(e.NotificationHandle = hSwitchNotify) Anzeigen des 'Zähler'-Wertes// Displaying the 'count' value Einstellen der ProgressBar auf den aktuellen Schritt// Setting the ProgressBar to the current step Die Farben der Grafiken entsprechened der Variablen anpassen// Adapt colors of graphice according to the variablesif (binReader.ReadBoolean() = true)ĭeviceUp_LED.Foreground = newSolidColorBrush(Colors.Red) ĭeviceUp_LED.Foreground = newSolidColorBrush(Colors.White) Įlse if(e.NotificationHandle = hDeviceDown)ĭeviceDown_LED.Foreground = newSolidColorBrush(Colors.Red) ĭeviceDown_LED.Foreground = newSolidColorBrush(Colors.White) Ermittlung welche Variable sich geändert hat// Detecting which variable has changedif(e.NotificationHandle = hDeviceUp) Setzen der Position von e.DataStream auf die des aktuellen benötigten Wertes// Setting the position of e.DataStream to the position of the current needed value -// wird bei Änderung einer SPS-Variablen aufgerufen// is activated when a PLC variable changes//-private void tcClient_OnNotification(object sender, AdsNotificationEventArgs e) The method is called if one of the PLC variables has changed. This method ('tcClient_OnNotification') is written next. TcClient.AdsNotification += newAdsNotificationEventHandler(tcClient_OnNotification) Ī method that does not exist yet was referred to above. Erstellen eines Events für Änderungen an den SPS-Variablen-Werten // Creating an event for changes of the PLC variable value HSwitchWrite = tcClient.CreateVariableHandle(".switch") Holen des Handles von 'switch' - wird für das Schreiben des Wertes benötigt// Getting the handle for 'switch' - needed for writing the value HSwitchNotify = tcClient.AddDeviceNotification(".switch", dataStream, 6, 1, AdsTransMode.OnChange, 10, 0, null) HCount = tcClient.AddDeviceNotification(".count", dataStream, 4, 2, AdsTransMode.OnChange, 10, 0, null) HSteps = tcClient.AddDeviceNotification(".steps", dataStream, 3, 1, AdsTransMode.OnChange, 10, 0, null) HDeviceDown = tcClient.AddDeviceNotification(".deviceDown", dataStream, 2, 1, AdsTransMode.OnChange, 10, 0, null) HDeviceUp = tcClient.AddDeviceNotification(".deviceUp", dataStream, 1, 1, AdsTransMode.OnChange, 10, 0, null) HEngine = tcClient.AddDeviceNotification(".engine", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, null) Initialisieren der Überwachung der SPS-Variablen// Initalizing the monitoring of the PLC variables The variables in the 'Load' method are then linked and linked with a method (that still has to be written), which is called when a variable changes. Eine neue Instanz der Klasse TcAdsClient erzeugen// Create an new instance of the TcAdsClient class Eine neue Instanz der Klasse BinaryReader erzeugen// Create a new instance of the BinaryReader classīinReader = new BinaryReader(dataStream)
Eine neue Instanz der Klasse AdsStream erzeugen// Create an new instance of the AdsStream class -// Wird als erstes beim Starten des Programms aufgerufen// Is activated first when the program is started//-private void Load(object sender, EventArgs e)
It is used to generate instances of different classes and create a link to port 801. The required namespaces 'System.IO' and 'TwinCAT.Ads' are inserted into the top line of the source code. Now the creation of the source code in C# can be started.