/// <summary> /// Unsubscribes the specified <paramref name="handler"/> from the controller with the specified <paramref name="controllerId"/>. /// The handler won't get executed on a change of the controller. /// </summary> /// <param name="controllerId">The id of the controller to not anymore observe.</param> /// <param name="handler">The handler to unsubscribe.</param> public void UnsubsribeFromControllerChanges(int controllerId, Action <IController> handler) { IController controller = ControllerTree.GetController(controllerId); foreach (Tag controllerTag in controller.GetAllAssociatedTags()) { controllerTag.ValueChanged -= NotifySubscribers; SlowTagListener.RemoveTag(controllerTag); } lock (_lockSubscribers) { _subscribers.RemoveAll(t => Equals(t.Item2, handler)); } }
/// <summary> /// Subscribes the specified <paramref name="handler"/> on the controller with the specified <paramref name="controllerId"/>. /// The handler gets executed whenever the controller changed a value. /// </summary> /// <param name="controllerId">The id of the controller to observe.</param> /// <param name="handler">The handler to get executed on a controller change.</param> public void SubscribeForControllerChanges(int controllerId, Action <IController> handler) { IController controller = ControllerTree.GetController(controllerId); lock (_lockSubscribers) { _subscribers.Add(new Tuple <int, Action <IController> >(controllerId, handler)); } foreach (Tag controllerTag in controller.GetAllAssociatedTags()) { SlowTagListener.AddTag(controllerTag); controllerTag.ValueChanged += NotifySubscribers; } SlowTagListener.RefreshAll(); }
public void Initialize(CancellationToken token, string name, string adsPath, int adsPort, string rootController, bool enableStateLogging = false) { _adsPath = adsPath; _adsPort = adsPort; _pathRootController = rootController; _enableSubStateLogging = enableStateLogging; Name = name; FastTagListener.Name = name; FastTagListener.AddressAndPath = adsPath + ":" + adsPort; SlowTagListener.Name = name; SlowTagListener.AddressAndPath = adsPath + ":" + adsPort; TagController.StartConnection(adsPath, adsPort); if (!TagController.IsConnected) { throw new Exception("Can't initialize " + name + " because connection to PLC failed! (Address: " + adsPath + ":" + adsPort); } FastTagListener.CommunicationProblemOccured += TagListenerCommunicationProblemOccurred; SlowTagListener.CommunicationProblemOccured += TagListenerCommunicationProblemOccurred; try { _plcSaberLoggerDchRecv = new GenericDataChannelListener <PlcSaberLoggerDataStruct>(FastTagListener, TagController); _plcSaberLoggerDchRecv.SetChannel("_pSaberLogger^.fbDataChannel", _pathRootController, "T_Logger_DCH"); _plcSaberLoggerDchRecv.DataReceived += PlcSaberLoggerDataReceived; _plcSaberLoggerDchRecv.CommunicationProblemOccured += PlcSaberLoggerCommunicationProblemOccured; } catch (Exception e) { _logger.Error("Initialization of Logger Datachannel failed:", e); } InitControllerTags(); ListenToPlcModuleActualValues(); ListenToPlcModuleState(enableStateLogging); Importer.Initialize(SlowTagListener, _adsPath, _adsPort, _pathRootController); _lastKeepAliveToggleTime = DateTime.Now; FastTagListener.RefreshAll(); SlowTagListener.RefreshAll(); }
public void Activate() { SlowTagListener.StartListening(_adsPath, _adsPort); FastTagListener.StartListening(_adsPath, _adsPort); }