Beispiel #1
0
        private static List <OpcTag> tagList;        //List where we keep our tags for manipulation.
        private static void SubscribeTags()
        {
            DataOtrilaTableAdapters.TagsTableAdapter tagsTableAdapter = new DataOtrilaTableAdapters.TagsTableAdapter();
            tagList = new List <OpcTag>();
            DataOtrila data = new DataOtrila();

            tagsTableAdapter.Fill(data.Tags);
            foreach (DataOtrila.TagsRow row in data.Tags.Rows)
            {
                TagTypeE tagTypeE = TagTypeE.Digital;
                if (row.Type == 2)
                {
                    tagTypeE = TagTypeE.Analog;
                }

                OpcTag _tag = new OpcTag()
                {
                    TagID       = row.ID,
                    Tag         = row.Tag,
                    TagName     = row.Name,
                    OpcServer   = row.OpcServer,
                    RefreshRate = row.RefreshTime,
                    Scaling     = row.Scale,
                    Description = row.Description,
                    Unit        = row.Unit,
                    TagType     = tagTypeE,
                    Archiving   = row.Archive
                };
                _tag.StartSubscription();
                tagList.Add(_tag);
            }
        }
Beispiel #2
0
        private static void OpcTag_OpcItemHasChanged(object sender, OpcTag e)
        {
            //Everytime a tag changes this event is raised...
            DataOtrilaTableAdapters.TagLiveTableAdapter tagLiveTableAdapter = new DataOtrilaTableAdapters.TagLiveTableAdapter();
            DataOtrila data = new DataOtrila();

            tagLiveTableAdapter.Fill(data.TagLive);


            if (tagLiveTableAdapter.GetByTagName(e.TagName).Count == 0)
            {
                bool typ = false;
                if (e.TagType == TagTypeE.Analog)
                {
                    typ = true;
                }
                tagLiveTableAdapter.Insert(e.TagID, e.TagName, e.NewValue, typ, false, DateTime.Now);
                tagList.Add(e);
            }
            else
            {
                tagLiveTableAdapter.UpdateValue(e.NewValue, DateTime.Now.ToString(), e.TagID);  //Update table
                //Update the list also.
                for (int i = 0; i < tagList.Count; i++)
                {
                    if (e.TagID == tagList[i].TagID)
                    {
                        tagList[i].NewValue = e.NewValue;
                    }
                }
            }
            //Archive here
            if (e.Archiving == true)
            {
                (new DataOtrilaTableAdapters.TagArchivesTableAdapter()).Insert(e.TagID, e.TagName, e.Tag, e.OpcServer, DateTime.Now, e.NewValue);
            }
        }