Samples WPF Private hEngine As Integer Private hDeviceUp As Integer Private hDeviceDown As Integer Private hSteps As Integer Private hCount As Integer Private hSwitchNotify As Integer Private hSwitchWrite As Integer Private tcClient As TwinCAT.Ads.TcAdsClient Private dataStream As TwinCAT.Ads.AdsStream Private binReader As System.IO.BinaryReader The first method is the 'Load' method. It is used to generate instances of different classes and create a link to port 801.
Private Sub Page1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded Try' Eine neue Instanz der Klasse AdsStream erzeugen ' Create a new instance of the AdsStream class dataStream = New AdsStream(7) ' Eine neue Instanz der Klasse BinaryReader erzeugen ' Create a new instance of the BinaryReader class binReader = New BinaryReader(dataStream) ' Eine neue Instanz der Klasse TcAdsClient erzeugen ' Create a new instance of the TcAdsClient class tcClient = New TwinCAT.Ads.TcAdsClient() ' Verbinden mit lokaler SPS - Laufzeit 1 - Port 801 ' Connecting to local PLC - Runtime 1 - Port 801 tcClient.Connect(801) Catch MessageBox.Show("Error while loading") End Try ...
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.
Try' Initialisieren der Ьberwachung der SPS-Variablen ' Initializing the monitoring of the PLC variables hEngine = tcClient.AddDeviceNotification(".engine", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, DBNull.Value) hDeviceUp = tcClient.AddDeviceNotification(".deviceUp", dataStream, 1, 1, AdsTransMode.OnCha nge, 10, 0, DBNull.Value) hDeviceDown = tcClient.AddDeviceNotification(".deviceDown", dataStream, 2, 1, AdsTransMode.O nChange, 10, 0, DBNull.Value) hSteps = tcClient.AddDeviceNotification(".steps", dataStream, 0, 1, AdsTransMode.OnChange, 1 0, 0, DBNull.Value) hCount = tcClient.AddDeviceNotification(".count", dataStream, 4, 2, AdsTransMode.OnChange, 1 0, 0, DBNull.Value) hSwitchNotify = tcClient.AddDeviceNotification(".switch", dataStream, 6, 1, AdsTransMode.OnC hange, 10, 0, DBNull.Value) ' Holen des Handles von "switch" - wird fьr das Schreiben des Wertes benцtigt ' Getting the handle for "switch" - needed for writing the value hSwitchWrite = tcClient.CreateVariableHandle(".switch") ' Erstellen eines Events fьr Дnderungen an den SPS-Variablen-Werten ' Creating an event for changes of the PLC variable valuesAddHandler tcClient.AdsNotificatio n, AddressOf tcClient_OnNotification Catch MessageBox.Show("Error when connecting") End Try End Sub 6.
Definition Linking PLC variables: The method AddDeviceNotification was used for linking the variables. public int AddDeviceNotification(string variableName, AdsStream dataStream, int offset, int length, AdsTransMode transMode, int cycleTime, int maxDelay, object userData); TX1000 40 Version: 1.2