Exemple #1
0
        private void btnGetTagInfo_Click(object sender, EventArgs e)
        {
            //Enable time-range picker
            btnGetTagData.Enabled = true;
            piStartTime.Enabled = true;
            piEndTime.Enabled = true;

            //Prefill time-range
            piStartTime.Text = "*-12h";
            piEndTime.Text = "*";

            //Clear chart
            piDataChart.Series["dataSeries"].Points.Clear();

            //Clear list of data
            lbPIData.Items.Clear();

            //Connect to server
            PIServers servers = new PIServers();
            PIServer server = servers[piServerPicker1.PIServer.ToString()];

            try
            {
                //Connect to server
                server.Connect();

                //Extract tag name
                string tagname = tbEnterTag.Text;

                //Search for tag
                IList<PIPoint> points = PIPoint.FindPIPoints(server, new List<string>() { tagname });

                if (points.Count == 1)
                {
                    lbTagFound.Text = "PI tag found!";

                    //Obtain pi point.
                    PIPoint point = PIPoint.FindPIPoint(server, tagname);

                    //Extract point attributes
                    IDictionary<string, object> pointAttribs = point.GetAttributes();

                    //Extract tag attributes
                    string tag = pointAttribs["tag"].ToString();
                    string descriptor = pointAttribs["descriptor"].ToString();
                    string engunits = pointAttribs["engunits"].ToString();
                    string pointtype = pointAttribs["pointtype"].ToString();
                    string pointsource = pointAttribs["pointsource"].ToString();
                    string creationdate = pointAttribs["creationdate"].ToString();
                    string creator = pointAttribs["creator"].ToString();
                    string location1 = pointAttribs["location1"].ToString();
                    string location2 = pointAttribs["location2"].ToString();
                    string location3 = pointAttribs["location3"].ToString();
                    string location4 = pointAttribs["location4"].ToString();
                    string location5 = pointAttribs["location5"].ToString();
                    string instrumenttag = pointAttribs["instrumenttag"].ToString();

                    //Set tag attributes in relevant text fields
                    piTag.Text = tag;
                    piDescriptor.Text = descriptor;
                    piEngUnits.Text = engunits;
                    piPointType.Text = pointtype;
                    piPointSource.Text = pointsource;
                    piCreationDate.Text = creationdate;
                    piCreator.Text = creator;
                    piLocation1.Text = location1;
                    piLocation2.Text = location2;
                    piLocation3.Text = location3;
                    piLocation4.Text = location4;
                    piLocation5.Text = location5;
                    piInstrumentTag.Text = instrumenttag;

                    piCurrentValue.Text = point.CurrentValue().ToString();
                    piCurrentTimestamp.Text = point.CurrentValue().Timestamp.ToString();

                    //Get data for the tag
                    btnGetTagData.PerformClick();

                } else if (points.Count > 1)
                {
                    //If more than one tag is found matching that name, skip.
                    //Application is designed to handle only one tag at a time.
                    lbTagFound.Text = "Single tag use only.";
                }
                else
                {
                    //If tag cannot be found display message
                    lbTagFound.Text = "PI tag not found.";
                }
            } catch (OSIsoft.AF.PI.PIAuthenticationException)
            {
                //If there is an authentication error trying to connect to the server, display message
                lbTagFound.Text = "Permissions Error!";
            }

            
            
        }