private void createLoader() { if (this._loader == null) { this._loader = (AdsSymbolLoader)this.OnCreateLoader(); } }
private ISymbolLoader OnCreateLoader() { if (!this._session.IsConnected) { throw new SessionNotConnectedException("Cannot create symbol loader!", this._session); } this._loader = this._session.Connection.CreateSymbolLoader(this._session, this._session.Settings.SymbolLoader); return(this._loader); }
public void CopyPasteTestDynamic() { using (TcAdsClient client = new TcAdsClient()) { client.Synchronize = false; // Connect to the target device client.Connect("164.4.4.112.1.1", 853); // Usage of "dynamic" Type and Symbols (>= .NET4 only) SymbolLoaderSettings settings = new SymbolLoaderSettings(SymbolsLoadMode.DynamicTree); IAdsSymbolLoader dynLoader = (IAdsSymbolLoader)SymbolLoaderFactory.Create(client, settings); // Set the Default setting for Notifications dynLoader.DefaultNotificationSettings = new AdsNotificationSettings(AdsTransMode.OnChange, 200, 2000); // Get the Symbols (Dynamic Symbols) dynamic dynamicSymbols = ((IDynamicSymbolLoader)dynLoader).SymbolsDynamic; dynamic adsPort = dynamicSymbols.TwinCAT_SystemInfoVarList._AppInfo.AdsPort; // Access Main Symbol with Dynamic Language Runtime support (DLR) // Dynamically created property "Main" // dynamic symMain = dynamicSymbols.Main; // Main is an 'VirtualSymbol' / Organizational unit that doesn't have a value // Calling ReadValue is not allowed // bool test = symMain.HasValue; // dynamic invalid = symMain.ReadValue(); // Reading TaskInfo Value // With calling ReadValue() a 'snapshot' of the Symbols Instance is taken dynamic vTaskInfoArray = dynamicSymbols.TwinCAT_SystemInfoVarList._TaskInfo.ReadValue(); // Getting the Snapshot time in UTC format DateTime timeStamp1 = vTaskInfoArray.UtcTimeStamp; // Getting TaskInfo Symbol for Task 1 dynamic symTaskInfo1 = dynamicSymbols.TwinCAT_SystemInfoVarList._TaskInfo[1]; // Getting CycleCount Symbol dynamic symCycleCount = symTaskInfo1.CycleCount; // Take Snapshot value of the ApplicationInfo struct dynamic vAppInfo = dynamicSymbols.TwinCAT_SystemInfoVarList._AppInfo.ReadValue(); // Get the UTC Timestamp of the snapshot DateTime timeStamp2 = vAppInfo.UtcTimeStamp; // Access the ProjectName of the ApplicationInfo Snapshot (type-safe!) string projectNameValue = vAppInfo.ProjectName; // Reading the CycleCount Value uint cycleCountValue = symTaskInfo1.CycleCount.ReadValue(); // Taking a Value Snapshot // Registering for dynamic "ValueChanged" events for the Values // Using Default Notification settings symCycleCount.ValueChanged += new EventHandler <ValueChangedArgs>(CycleCountValueChanged); // Override default notification settings symTaskInfo1.NotificationSettings = new AdsNotificationSettings(AdsTransMode.Cyclic, 500, 0); // Register for ValueChanged event. symTaskInfo1.ValueChanged += new EventHandler <ValueChangedArgs>(TaskInfo1ValueValueChanged); // Struct Type Thread.Sleep(10000); // Sleep main thread for 10 Seconds } Console.WriteLine("CycleCount Changed events received: {0}", cycleCountEvents); Console.WriteLine("taskInfo1 Changed events received: {0}", taskInfo1Events); }