/// <summary> /// Creates a new <see cref="Controller"/> instance. /// </summary> /// <param name="tagController">The tag controller used by the created controller.</param> /// <param name="controllerTag">The tag, the new controller is dependend on.</param> /// <param name="userDefinedInterfaces">User defined interfaces</param> /// <param name="tagListener">A tag listener instance</param> /// <returns>A new <see cref="Controller"/> instance.</returns> public Controller Create( ITagController tagController, IControllerTag controllerTag, IList <string> userDefinedInterfaces, ITagListener tagListener) { var controller = Create(tagController, controllerTag, tagListener); if (userDefinedInterfaces != null) { tagListener.AddUdtHandler <Command>(CmdList.PlcArrayDataType()); foreach (var userDefinedInterface in userDefinedInterfaces.Where(value => !string.IsNullOrWhiteSpace(value))) { var path = TagName.SpecificInterface(parent: null).AppendTagName(userDefinedInterface); var userDefinedInterfaceTags = ChildTagsFromPath(controllerTag, path); controller.AddUserDefinedInterface(path, userDefinedInterfaceTags); // create the commands foreach (var userDefinedInterfaceTag in userDefinedInterfaceTags) { var commands = CreateCommands(controllerTag, controller, userDefinedInterfaceTag, tagListener); controller.UpdateUserDefinedCommands(userDefinedInterfaceTag.NestedName, commands.ToList()); } } } return(controller); }
public void AddTagListener(ITagListener tagListener) { if (tagListener != null) { _tagListeners.Add(tagListener); } }
public DataChannelWriter(ITagListener tagListener, ITagController tagController) { _tagListener = tagListener; _tagController = tagController; PollingRate = DefaultPollingRate; Timeout = DefaultTimeout; }
/// <summary> /// Initializes this alarms importer. /// </summary> /// <param name="tagListener">The tag listener to get used by this instance.</param> public void Initialize(ITagListener tagListener) { _logger.Debug(string.Format("Initializing alarms importer on '{0}'", tagListener)); _tagListener = tagListener; _alarmsArrayTag = InitializeGlobalAlarmsTag(); _alarmsArrayTag.ValueChanged += HandleAlarmsChanged; _tagListener.AddTag(_alarmsArrayTag); }
public void SetUp() { _tagListener = new BeckhoffPollingTagListener(Global.AdsAddress, Global.AdsPort, new GlobalLock()); _tagImporter = new BeckhoffOnlineTagImporter(Global.AdsAddress, Global.AdsPort); _testee = new BeckhoffOnlineControllerTreeImporter(_tagImporter); _tagListener.StartListening(); _testee.Initialize(_tagListener, Global.AdsAddress, Global.AdsPort); }
public void SetUp() { var logger = new Log4NetLogger(); _tagController = new BeckhoffTagController(Global.AdsAddress, Global.AdsPort, logger); _tagListener = new BeckhoffPollingTagListener(Global.AdsAddress, Global.AdsPort, new GlobalLock(), logger); _tagController.StartConnection(); _tagListener.StartListening(); }
public BeckhoffOnlineControllerTreeImporter(ITagImporter tagImporter) { _twinCatClient = new TwinCatClientWrapper(); _tagController = new BeckhoffTagController(); _tagListener = new BeckhoffPollingTagListener(); _alarmsImporter = new BeckhoffOnlineAlarmsImporter(); _findControllerTags = new ControllerTagFinder(tagImporter, new Log4NetLogger()); _createController = new ControllerFactory(); _logger = new Log4NetLogger(); _controllerTree = new ControllerTree(); }
public void SetUp() { _logger = new Log4NetLogger(); _tagController = new BeckhoffTagController(Global.AdsAddress, Global.AdsPort, _logger); _tagListener = new BeckhoffPollingTagListener(Global.AdsAddress, Global.AdsPort, new GlobalLock(), _logger); _tagController.StartConnection(); _tagListener.StartListening(); _tagImporter = new BeckhoffOnlineTagImporter(_logger); _tagImporter.Initialize(Global.AdsAddress, Global.AdsPort); }
public void SetUp() { _tagController = new BeckhoffTagController(Global.AdsAddress, Global.AdsPort); _tagListener = new BeckhoffPollingTagListener(Global.AdsAddress, Global.AdsPort, new GlobalLock()); _alarmsImporter = new BeckhoffOnlineAlarmsImporter(Global.AdsAddress, Global.AdsPort, new GlobalLock()); _alarmsImporter.Initialize(_tagListener); _tagController.StartConnection(); _tagListener.StartListening(); // prepare test by clear out all alarms _tagController.WriteTag(WriteTags.GlobalAlarmsCommandTag, WriteTags.ClearAllAlarmsCommand).Wait(); Thread.Sleep(500); }
public void SetUp() { _tag = new Tag("fbAGS_1.udiAlarmId", "MiddlePRG_1", "UDINT", Global.AdsPort); _tagController = new BeckhoffTagController(Global.AdsAddress, Global.AdsPort); _tagController.StartConnection(); _tagListener = new BeckhoffPollingTagListener(Global.AdsAddress, Global.AdsPort, new GlobalLock()); _tagListener.StartListening(); try { _tagController.WriteTag(_tag, 0).Wait(1000); } catch (Exception e) { Assert.Fail("Cannot setup test because writing initial values to PLC failed. " + e.Message); } }
public BeckhoffOnlineControllerTreeImporter( ITwinCatClient twinCatClient, ITagController tagController, ITagListener tagListener, IFindControllerTags findControllerTags, ICreateController createController, IAlarmsImporter alarmsImporter, ILogger logger) { _twinCatClient = twinCatClient; _tagController = tagController; _tagListener = tagListener; _alarmsImporter = alarmsImporter; _findControllerTags = findControllerTags; _createController = createController; _logger = logger; _controllerTree = new ControllerTree(); }
/// <summary> /// Initializes this instance with all necessary information needed to import controller trees. /// </summary> /// <param name="tagListener">The tag listener used to register the tags of the imported controller on.</param> /// <param name="path">The connection string or path (file path or IP address depending on implementation). In case of Beckhoff this is the AdsAddress.</param> /// <param name="port">The ADS Port in case of Beckhoff implementation.</param> /// <param name="rootController">The plcAddress of the root controller</param> public virtual void Initialize( ITagListener tagListener, string path, int port = 0, string rootController = "") { if (_controllerTree.IsInitialized) { return; } _tagListener = tagListener; _adsAddress = path; _adsPort = port; _rootController = rootController; _logger.Init(typeof(BeckhoffOnlineControllerTreeImporter)); _twinCatClient.Initialize(path, port); _tagController.StartConnection(path, port); _alarmsImporter.Initialize(tagListener); _findControllerTags.Initialize(_tagListener, _adsAddress, _adsPort); }
public void SetListener(ITagListener listener) { ClearListeners(); RegisterListener(listener); }
public void RegisterListener(ITagListener listener) { TagListeners.Add(listener); }
public void start(ITagListener Listener) { this.listener = Listener; this.start(udp_port); }
public void Initialize(ITagListener tagListener, string path, int port = 0, string rootController = "") { }
/// <summary> /// Initializes the instance with the specified items. /// </summary> /// <param name="tagListener">The tag listener this instance uses to read tags.</param> /// <param name="address">The address under which the tags can be found.</param> /// <param name="port">The port under which the the tags can be found.</param> public void Initialize(ITagListener tagListener, string address, int port = 0) { _tagListener = tagListener; _tagImporter.Initialize(address, port); }
/// <summary> /// Creates a new <see cref="Controller"/> instance. /// </summary> /// <param name="tagController">The tag controller used by the created controller.</param> /// <param name="controllerTag">The tag, the new controller is dependend on.</param> /// <param name="tagListener">A tag listener instance.</param> /// <returns>A new <see cref="Controller"/> instance.</returns> public Controller Create(ITagController tagController, IControllerTag controllerTag, ITagListener tagListener) { Controller controller = CreateControllerInstance(tagController, controllerTag); IEnumerable <Impl.Command> commands = CreateCommands(controllerTag, controller); controller.UpdateCommands(commands); controller.AddCommonInterfaceTags(CommonInterfaceTagsFrom(controllerTag)); controller.AddParameters(ChildTagsFromPath(controllerTag, TagName.SpecificInterface(parent: null).Parameters())); controller.AddActualValues(ChildTagsFromPath(controllerTag, TagName.SpecificInterface(parent: null).ActualValues())); controller.AddConfigurations(ChildTagsFromPath(controllerTag, TagName.SpecificInterface(parent: null).Configurations())); controller.AddOutputs(ChildTagsFromPath(controllerTag, TagName.SpecificInterface(parent: null).Outputs())); controller.AddInputs(ChildTagsFromPath(controllerTag, TagName.SpecificInterface(parent: null).Inputs())); controller.AddPossibleAlarms(ReadPossibleAlarms(controllerTag, tagListener)); return(controller); }
private IEnumerable <PossibleAlarm> ReadPossibleAlarms(IControllerTag controllerTag, ITagListener tagListener) { // TODO: we assume that the order is right here (ToArray) but the interface should be changed from IEnumerable to IList Tag[] alarmTags = ChildTagsFromPath(controllerTag, TagName.SpecificInterface(parent: null).Alarms()).ToArray(); var alarms = new Collection <PossibleAlarm>(); for (int i = 0; i < alarmTags.Count(); i++) { var alarmTag = alarmTags[i]; var alarm = new PossibleAlarm(); var almText = alarmTag.Childs.First(c => c.NestedName == "strText"); tagListener.ReadTagSynchronously(almText); alarm.Text = (string)almText.Value; if (string.IsNullOrEmpty(alarm.Text)) { continue; } var almType = alarmTag.Childs.First(c => c.NestedName == "eAlmClass"); tagListener.ReadTagSynchronously(almType); alarm.AlarmType = (short)almType.Value; alarm.FullControllerPath = controllerTag.GetScopedPath(); Tag machineNumberTag = new Tag(NamingConventions.PathMachineNumber, NamingConventions.Global, "UDINT"); tagListener.ReadTagSynchronously(machineNumberTag); // Alarm-ID calculation, see FB_Alm_Man.setAlarm // InAlmElement.udiNr := 100000*InAlmElement.udiMachineNr + INT_TO_UDINT(100*InAlmElement.intCtrlId) + InAlmElement.udiAlarmNr; var alarmId = 100000 * (uint)machineNumberTag.Value + 100 * controllerTag.GetControllerId() + i; alarm.AlarmId = (uint)alarmId; alarms.Add(alarm); } return(alarms); }
private IEnumerable <Impl.Command> CreateCommands( IControllerTag controllerTag, Controller controller, Tag userDefinedInterfaceTag, ITagListener tagListener) { var commandsTag = controller.FindTag(TagName.CmdList(parent: null), userDefinedInterfaceTag); if (commandsTag != null) { Tag modeTag = null; Tag commandTag = null; // assuming that the job interface is defined in the parent tag of the commandsTag var jobTag = commandsTag.Parent; // get the mode tag modeTag = controller.FindTag(TagName.Mode(parent: null), jobTag); commandTag = controller.FindTag(TagName.ManualCommand(parent: null), jobTag); if (jobTag.NestedName != TagName.Job(parent: null) || modeTag == null || commandTag == null) { throw new InvalidOperationException(new StringBuilder() .AppendFormat("The {0} is not defined inside a {1} structure for the controller {2} or ", TagName.CmdList(parent: null), TagName.Job(parent: null), controller.Name) .AppendFormat("the {0} or {1} was not defined in the {2} structure. ", TagName.Mode(parent: null), TagName.ManualCommand(parent: null), TagName.Job(parent: null)) .AppendLine() .AppendFormat("Set the {0} as a subelement of a valid {1} structure.", commandsTag.Name, TagName.Job(parent: null)).ToString()); } tagListener.ReadTagSynchronously(commandsTag); var commands = commandsTag.ArrayValues <Command>(); int commandIndex = 0; if (commands.Any(c => c == null)) { throw new InvalidOperationException(new StringBuilder() .AppendFormat("The commands {0} of the controller {1} could not be read. ", commandsTag.Name, controller.Name) .AppendLine() .AppendFormat("Expected array datatype {0}.", CmdList.PlcArrayDataType()) .AppendLine() .AppendFormat("Current array datatype {0}.", commandsTag.DataType).ToString()); } foreach (Command command in commands.Where(c => c != null && !c.Name.IsNullOrEmpty())) { Tag tag = controller.FindTag(TagName.CmdList(null, commandIndex), commandsTag); if (tag == null) { continue; } var commandImpl = new Impl.Command(controller, command, tag.Childs.ToReadOnly(), modeTag, commandTag); yield return(commandImpl); commandIndex++; } // remove CmdListArray-Tag in order to prevent that the same tags exists more // than once --> For example the tag "bolAvailable" jobTag.Childs.Remove(commandsTag); } }
public DataChannelListener(ITagListener tagListener, ITagController tagController) { _tagListener = tagListener; _tagController = tagController; }
public void Initialize(ITagListener tagListener) { }
/// <summary> /// Initializes a new <see cref="BeckhoffOnlineAlarmsImporter" /> instance. /// </summary> /// <param name="adsAddress">The ads address the tag listener should communicate with.</param> /// <param name="adsPort">The ads port the tag listener should communicate with.</param> /// <param name="globalLock">The global lock is a singleton and hold a global semaphor needed for TagListener synchronization.</param> /// <remarks> /// This constructor mainly exists because of backwards compatibility. It will not create an own /// <see cref="ITagListener" /> instance which means, that the initialize method must get called. /// </remarks> public BeckhoffOnlineAlarmsImporter(string adsAddress, int adsPort, IGlobalLock globalLock) : this() { _tagListener = new BeckhoffPollingTagListener(adsAddress, adsPort, globalLock); }