Samples WPF variableName: name of the PLC variable. dataStream: data stream receiving the data. offset: interval in the data stream. length: length in the data stream. transMode: event if the variable changes. cycletime: time (in ms) after which the PLC server checks whether the variable has changed. maxDelay: latest time (in ms) after which the event has finished. userData: object that can be used for storing certain data. The method CreateVariableHandle was used for linking the variable 'hSwitchWrite'. int TcAdsClient.CreateVariableHandle(string variableName); variableName: name of the PLC variable. 7. Writing the method: A method that does not exist yet was referred to above.
This method ('tcClient_OnNotification') is written next. The method is called if one of the PLC variables has changed.
'------------------------------------------------' wird bei Дnderung einer SPS- Variablen aufgerufen' is activated when a PLC variable changes'------------------------------------- ----------- Private Sub tcClient_OnNotification(ByVal sender As Object, ByVal e As AdsNotificationEventArgs) Try' 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 e.DataStream.Position = e.Offset ' Ermittlung welche Variable sich geдndert hat ' Detecting which variable has changedIf (e.NotificationHandle = hDeviceUp) Then'Die Farben der Grafiken entsprechened der Variablen anpassen 'Adapt colors of graphics according to the variablesIf (binReader.ReadBoolean() = True) Then DeviceUp_LED.Foreground = New SolidColorBrush(Colors.Red) Else DeviceUp_LED.Foreground = New SolidColorBrush(Colors.White) End If ElseIf (e.NotificationHandle = hDeviceDown) Then If (binReader.ReadBoolean() = True) Then DeviceDown_LED.Foreground = New SolidColorBrush(Colors.Red) Else DeviceDown_LED.Foreground = New SolidColorBrush(Colors.White) End If ElseIf (e.NotificationHandle = hSteps) Then' Einstellen der ProgressBar auf den aktuellen Sc hritt ' Setting the ProgressBar to the current step prgSteps.Value = (binReader.ReadByte() * 4) ElseIf (e.NotificationHandle = hCount) Then' Anzeigen des "count"-Werts ' Displaying the "count" value lblCount.Content = binReader.ReadUInt16().ToString() ElseIf (e.NotificationHandle = hSwitchNotify) Then' Markieren des korrekten RadioButtons ' Checking the correct RadioButtonIf (binReader.ReadBoolean() = True) Then optSpeedFast.IsChecked = TrueElse optSpeedSlow.IsChecked = True End If End If Catch MessageBox.Show("Error") End Try End Sub There are still two methods missing for setting the speed of the machine.
They are used to switch a virtual switch by writing a value to the PLC variable 'switch'. '------------------------------------------------------' wird aufgerufen, wenn das Feld 'schnell' ma rkiert wird' is activated when the 'fast' field is marked'------------------------------------------ ------------ Private Sub optSpeedFast_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Ha ndles optSpeedFast.Click TX1000 41 Version: 1.2