Samples WPF } catch { MessageBox.Show("Fehler beim Laden"); } //... 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// Initalizing the monitoring of the PLC variables hEngine = tcClient.AddDeviceNotification(".engine", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, null); hDeviceUp = tcClient.AddDeviceNotification(".deviceUp", dataStream, 1, 1, AdsTransMode.OnChange, 10, 0, null); hDeviceDown = tcClient.AddDeviceNotification(".deviceDown", dataStream, 2, 1, AdsTransMode.OnCha nge, 10, 0, null); hSteps = tcClient.AddDeviceNotification(".steps", dataStream, 3, 1, AdsTransMode.OnChange, 10, 0 , null); hCount = tcClient.AddDeviceNotification(".count", dataStream, 4, 2, AdsTransMode.OnChange, 10, 0 , null); hSwitchNotify = tcClient.AddDeviceNotification(".switch", dataStream, 6, 1, AdsTransMode.OnChan ge, 10, 0, null); // 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 value tcClient.AdsNotification += newAdsNotificationEventHandler(tcClient_OnNotification); } catch (Exception ex) { MessageBox.Show(ex.Message); } } 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); 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. TX1000 33 Version: 1.2