Exemplo n.º 1
0
        /// <summary>
        /// Creates tag groups according to the specified template.
        /// </summary>
        protected virtual List <TagGroup> CreateTagGroups(DeviceTemplate deviceTemplate, ref int tagInd)
        {
            List <TagGroup> tagGroups = new List <TagGroup>();

            if (deviceTemplate != null)
            {
                foreach (ElemGroup elemGroup in deviceTemplate.ElemGroups)
                {
                    TagGroup tagGroup = new TagGroup(elemGroup.Name);
                    tagGroups.Add(tagGroup);
                    elemGroup.StartKPTagInd = tagInd;

                    foreach (Elem elem in elemGroup.Elems)
                    {
                        int signal = ++tagInd;
                        tagGroup.AddNewTag(signal, elem.Name);

                        if (elem.ElemType == ElemType.Float || elem.ElemType == ElemType.Double)
                        {
                            floatSignals.Add(signal);
                        }
                    }
                }
            }

            return(tagGroups);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the device tags.
        /// </summary>
        private void InitDeviceTags()
        {
            tagsByCnlNum = new Dictionary <int, KPTag>();
            List <TagGroup> tagGroups = new List <TagGroup>(deviceConfig.Subscriptions.Count);
            int             signal    = 1;

            foreach (SubscriptionConfig subscriptionConfig in deviceConfig.Subscriptions)
            {
                TagGroup tagGroup = new TagGroup(subscriptionConfig.DisplayName);
                tagGroups.Add(tagGroup);

                foreach (ItemConfig itemConfig in subscriptionConfig.Items)
                {
                    bool cnlNumSpecified = itemConfig.CnlNum > 0;

                    if (itemConfig.IsArray)
                    {
                        for (int i = 0, n = itemConfig.ArrayLen; i < n; i++)
                        {
                            KPTag kpTag = tagGroup.AddNewTag(signal++, itemConfig.DisplayName + "[" + i + "]");
                            itemConfig.Tag = itemConfig.Tag ?? kpTag; // store a reference to the 1st tag

                            if (cnlNumSpecified)
                            {
                                tagsByCnlNum[itemConfig.CnlNum + i] = kpTag;
                            }
                        }
                    }
                    else
                    {
                        KPTag kpTag = tagGroup.AddNewTag(signal++, itemConfig.DisplayName);
                        itemConfig.Tag = kpTag;

                        if (cnlNumSpecified)
                        {
                            tagsByCnlNum[itemConfig.CnlNum] = kpTag;
                        }
                    }
                }
            }

            InitKPTags(tagGroups);
        }