Пример #1
0
 public RootController(
     ITagController tagController,
     IControllerTag controllerTag)
     : base(tagController, controllerTag)
 {
     _autoModeCommand = new SetAll2AutoModeCommand(this);
 }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <summary>
        /// Imports all controllers from the specified path and port
        /// and searchs for user defined interfaces for each controller.
        /// </summary>
        public void ImportAllControllers(IList <string> userDefinedInterfaces)
        {
            _logger.Debug(string.Format("Import controller tree skeleton on '{0}:{1}'", _adsAddress, _adsPort));
            _alarmsImporter.ImportAlarms();
            IReadOnlyCollection <IControllerTag> controllerTags = _findControllerTags.FindControllerTags();

            if (controllerTags.IsNullOrEmpty())
            {
                return;
            }
            IControllerTag anyControllerTag = controllerTags.First();

            _tagListener.AddUdtHandler <CtrlCommonInterface>(anyControllerTag.GetCommonInterfaceDataType());
            foreach (IControllerTag controllerTag in controllerTags)
            {
                Tag commonInterfaceTag = controllerTag.GetCommonInterfaceTag();
                if (commonInterfaceTag != null)
                {
                    _tagListener.ReadTagSynchronously(commonInterfaceTag);
                }
            }
            Controller controller = ImportControllerWithChildren(_rootController, controllerTags, userDefinedInterfaces, MaxChildImportDepth);

            _controllerTree.Initialize(controller);
            _alarmsImporter.AlarmsChanged += alarms => _controllerTree.UpdateAlarms(alarms);
            _controllerTree.UpdateAlarms(_alarmsImporter.GetAllImportedAlarms());
            _logger.Debug(string.Format("Finished import of controller skeleton tree on '{0}:{1}'", _adsAddress, _adsPort));
        }
Пример #4
0
 private Controller CreateControllerInstance(ITagController tagController, IControllerTag controllerTag)
 {
     if (controllerTag.GetParentControllerId() == NoControllerId)
     {
         return(new RootController(tagController, controllerTag));
     }
     return(new Controller(tagController, controllerTag));
 }
Пример #5
0
        private IEnumerable <Tag> ChildTagsFromPath(IControllerTag controllerTag, string path)
        {
            Tag tagUnderPath = controllerTag.Tag.GetChildTagUnderPath(path);

            if (tagUnderPath == null)
            {
                yield break;
            }
            foreach (Tag child in tagUnderPath.Childs)
            {
                yield return(child);
            }
        }
Пример #6
0
        private IEnumerable <Tag> CommonInterfaceTagsFrom(IControllerTag controllerTag)
        {
            string jobTagName = TagName.CommonInterface(parent: null).Job();
            Tag    jobTag     = controllerTag.Tag.GetChildTagUnderPath(jobTagName);

            if (jobTag == null)
            {
                yield break;
            }
            foreach (Tag tag in jobTag.Childs.Where(t => !string.Equals(t.NestedName, NamingConventions.CmdList)))
            {
                yield return(tag);
            }
        }
Пример #7
0
        /// <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);
        }
Пример #8
0
        private IEnumerable <Impl.Command> CreateCommands(IControllerTag controllerTag, Controller controller)
        {
            int commandIndex = 0;

            foreach (Command command in controllerTag.GetCommands())
            {
                string tagPath = TagName.CommonInterface(parent: null).Job().CmdList().CmdList(commandIndex);
                Tag    tag     = controllerTag.Tag.GetChildTagUnderPath(tagPath);
                if (tag == null)
                {
                    continue;
                }
                var commandImpl = new Impl.Command(controller, command, tag.Childs.ToReadOnly());
                yield return(commandImpl);

                commandIndex++;
            }
        }
Пример #9
0
        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);
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Controller"/> class.
 /// </summary>
 public Controller(
     ITagController tagController,
     IControllerTag controllerTag)
 {
     _tagController                        = tagController;
     _controllerTag                        = controllerTag;
     _children                             = new ConcurrentBag <Controller>();
     _alarms                               = new ConcurrentDictionary <uint, Alarm>();
     _possibleAlarms                       = new ConcurrentBag <PossibleAlarm>();
     _parameters                           = new ConcurrentBag <Tag>();
     _configurations                       = new ConcurrentBag <Tag>();
     _actualValues                         = new ConcurrentBag <Tag>();
     _inputs                               = new ConcurrentBag <Tag>();
     _outputs                              = new ConcurrentBag <Tag>();
     _commonInterfaceTags                  = new ConcurrentBag <Tag>();
     _commands                             = new ConcurrentBag <Command>();
     AlarmAdded                           += () => { };
     AlarmRemoved                         += () => { };
     AlarmReplaced                        += () => { };
     CommonInformationChanged             += () => { };
     GetCommonInterfaceTag().ValueChanged += (s, e) => CommonInformationChanged();
 }
Пример #11
0
        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);
            }
        }