コード例 #1
0
        public void Run()
        {
            PIServers piServers = new PIServers();
            PIServer  piServer  = piServers["<PISERVER>"];

            IList <PIPoint> points = PIPoint.FindPIPoints(piServer, new[] { "sample_floatpoint", "sample_digitalpoint" });

            PIPoint floatingPIPoint = points[0];
            PIPoint digitalPIPoint  = points[1];

            AFEnumerationSet digSet = piServer.StateSets["Modes"];

            IList <AFValue> valuesToWrite = new List <AFValue>();

            for (int i = 0; i < 10; i++)
            {
                AFTime time = new AFTime(new DateTime(2015, 1, 1, i, 0, 0, DateTimeKind.Local));

                AFValue afValueFloat = new AFValue(i, time);
                // Associate the AFValue to a PI Point so we know where to write to.
                afValueFloat.PIPoint = floatingPIPoint;

                AFEnumerationValue digSetValue    = i % 2 == 0 ? digSet["Auto"] : digSet["Manual"];
                AFValue            afValueDigital = new AFValue(digSetValue, time);
                afValueDigital.PIPoint = digitalPIPoint;

                valuesToWrite.Add(afValueFloat);
                valuesToWrite.Add(afValueDigital);
            }

            // Perform a bulk write. Use a single local call to PI Buffer Subsystem if possible.
            // Otherwise, make a single call to the PI Data Archive.
            // We use no compression just so we can check all the values are written.
            piServer.UpdateValues(valuesToWrite, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible);
        }
コード例 #2
0
        private AFValue Calculate(AFTime time, AFAttributeList inputAttributes, AFValues inputValues)
        {
            if (time == null)
            {
                throw new ArgumentException("No timestamp");
            }

            if (inputAttributes == null || inputAttributes.Count == 0)
            {
                throw new ArgumentException("No input attributes");
            }

            if (inputValues == null || inputValues.Count == 0)
            {
                throw new ArgumentException(Resources.ERR_NoInputValues);
            }

            AFValue inVal;

            if (inputAttributes.Count > 0)
            {
                inVal = inputAttributes[0].GetValue(time);

                if (inVal == null)
                {
                    throw new ApplicationException("Input value is null");
                }
                else
                {
                    AFEnumerationValue enumValue = inVal.Value as AFEnumerationValue;
                    if (enumValue != null && enumValue.Value == 248)
                    {
                        // Attempting to handle an error when the output value is 248 instead of the NoData state
                        return(AFValue.CreateSystemStateValue(this.Attribute, AFSystemStateCode.NoData, time));
                    }
                    else
                    {
                        double keyValue    = (double)inVal.Value;
                        double resultValue = GetCalibratedValue(keyValue);

                        if (!double.IsNaN(resultValue))
                        {
                            return(new AFValue(this.Attribute, resultValue, inVal.Timestamp, this.Attribute.DefaultUOM));
                        }
                        else
                        {
                            return(AFValue.CreateSystemStateValue(this.Attribute, AFSystemStateCode.NoData, time));
                        }
                    }
                }
            }
            else
            {
                throw new ApplicationException(string.Format("Input attribute not found (#{0}", 1));
            }
        }
コード例 #3
0
        public void DeleteEnumerationValueTest()
        {
            string path = Constants.AF_ENUMERATION_VALUE_PATH;

            instance.DeleteEnumerationValue(webId);
            AFDatabase db = StandardPISystem.Databases[Constants.AF_DATABASE_NAME];

            db.Refresh();
            AFEnumerationValue afEnumValue = AFObject.FindObject(path) as AFEnumerationValue;

            Assert.IsNull(afEnumValue);
            DeleteSampleDatabaseForTests();
            CreateSampleDatabaseForTests();
        }
コード例 #4
0
        private static void SetAttributeValues(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            AFElement meter001 = database.Elements["Meters"].Elements["Meter001"];

            meter001.Attributes["Substation"].SetValue(new AFValue("SSA-01"));
            meter001.Attributes["Usage Limit"].SetValue(new AFValue(350));
            meter001.Attributes["Building"].SetValue(new AFValue("The Shard"));

            AFEnumerationValue bTypeValue = database.EnumerationSets["Building Type"]["Residential"];

            meter001.Attributes["Building Type"].SetValue(new AFValue(bTypeValue));
            meter001.Attributes["City"].SetValue(new AFValue("London"));
        }
コード例 #5
0
        private static void SetAttributeValues(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            AFElement meter001 = database.Elements["Meters"].Elements["Meter001"];

            meter001.Attributes["Substation"].SetValue(new AFValue("Edinburgh"));
            meter001.Attributes["Usage Limit"].SetValue(new AFValue(350));
            meter001.Attributes["Building"].SetValue(new AFValue("Gryffindor"));

            AFEnumerationValue bTypeValue = database.EnumerationSets["Building Type"]["Residential"];

            meter001.Attributes["Building Type"].SetValue(new AFValue(bTypeValue));
            meter001.Attributes["District"].SetValue(new AFValue("Hogwarts"));
        }
コード例 #6
0
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["Basic-AFSDK-Sample"];

            AFElement boilerA = afDatabase.Elements["Region_0"].Elements["BoilerA"];

            AFElementTemplate   elementTemplate         = afDatabase.ElementTemplates["BasicBoilerTemplate"];
            AFAttributeTemplate temperatureAttrTemplate = elementTemplate.AttributeTemplates["Temperature"];
            AFAttributeTemplate modeAttrTemplate        = elementTemplate.AttributeTemplates["Mode"];

            AFElement.LoadAttributes(new[] { boilerA }, new[] { temperatureAttrTemplate, modeAttrTemplate });

            AFEnumerationSet digSet = afDatabase.EnumerationSets["Modes"];

            IList <AFValue> valuesToWrite = new List <AFValue>();

            for (int i = 0; i < 10; i++)
            {
                AFTime time = new AFTime(new DateTime(2015, 1, 1, i, 0, 0, DateTimeKind.Local));

                AFValue afValueFloat = new AFValue(i, time);
                // Associate the AFValue to an attribute so we know where to write to.
                afValueFloat.Attribute = boilerA.Attributes["Temperature"];

                AFEnumerationValue digSetValue    = i % 2 == 0 ? digSet["Auto"] : digSet["Manual"];
                AFValue            afValueDigital = new AFValue(digSetValue, time);
                afValueDigital.Attribute = boilerA.Attributes["Mode"];

                valuesToWrite.Add(afValueFloat);
                valuesToWrite.Add(afValueDigital);
            }

            // Perform a bulk write. Use a single local call to PI Buffer Subsystem if possible.
            // Otherwise, make a single call to the PI Data Archive.
            // We use no compression just so we can check all the values are written.
            // AFListData is the class that provides the bulk write method.
            AFListData.UpdateValues(valuesToWrite, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible);
        }
コード例 #7
0
        public void UpdateEnumerationValueTest()
        {
            string             path             = Constants.AF_ENUMERATION_VALUE_PATH;
            PIEnumerationValue enumerationValue = instance.GetByPath(path, null);

            enumerationValue.Id          = null;
            enumerationValue.Description = "New enumeration value description";
            enumerationValue.Links       = null;
            enumerationValue.Path        = null;
            enumerationValue.WebId       = null;
            instance.UpdateEnumerationValue(webId, enumerationValue);

            StandardPISystem.Refresh();
            AFEnumerationValue afEnumValue = AFObject.FindObject(path) as AFEnumerationValue;

            afEnumValue.Database.Refresh();
            if (afEnumValue != null)
            {
                Assert.IsTrue(afEnumValue.Description == afEnumValue.Description);
            }
        }
コード例 #8
0
        public override AFValue GetValue(object context, object timeContext, AFAttributeList inputAttributes, AFValues inputValues)
        {
            if (!fChecked)
            {
                CheckConfig();
            }

            try {
                // Note that timeContext is an object.
                // We need to examine it further in order to resolve it to an AFTime.
                AFTime time;
                if (timeContext is AFTime)
                {
                    time = (AFTime)timeContext;
                }
                else if (timeContext is AFTimeRange)
                {
                    var timeRange = (AFTimeRange)timeContext;
                    time = (Attribute.Element is AFEventFrame) ? timeRange.StartTime : timeRange.EndTime;
                }
                else
                {
                    time = AFTime.NowInWholeSeconds;
                }

                // Important to note that the order of inputValues matches the order of inputAttributes.
                if (inputAttributes == null || inputAttributes.Count == 0)
                {
                    throw new ArgumentException("No input attributes");
                }

                if (inputValues == null || inputValues.Count == 0)
                {
                    throw new ArgumentException(Resources.ERR_NoInputValues);
                }

                if (TimestampType == "Attribute")
                {
                    if (inputValues.Count > 1)
                    {
                        AFValue tsVal  = inputValues[1];
                        object  objVal = tsVal.Value;
                        if (objVal != null)
                        {
                            if (Extensions.IsDateTimeVal(objVal))
                            {
                                time = new AFTime(objVal);
                            }
                            else
                            {
                                throw new ApplicationException(string.Format("Timestamp attribute must be datetime type {0}", objVal.ToString()));
                            }
                        }
                        else
                        {
                            throw new ApplicationException("Timestamp value is null");
                        }
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Input value not found (#{0}", 2));
                    }
                }

                if (inputAttributes.Count > 0)
                {
                    AFValue inVal = inputAttributes[0].GetValue(time);

                    if (inVal == null)
                    {
                        throw new ApplicationException("Input value is null");
                    }
                    else
                    {
                        AFEnumerationValue enumValue = inVal.Value as AFEnumerationValue;
                        if (enumValue != null && enumValue.Value == 248)
                        {
                            // Attempting to handle an error when the output value is 248 instead of the NoData state
                            return(AFValue.CreateSystemStateValue(Attribute, AFSystemStateCode.NoData, time));
                        }
                        else
                        {
                            return(new AFValue(Attribute, inVal.Value, inVal.Timestamp, Attribute.DefaultUOM));
                        }
                    }
                }
                else
                {
                    throw new ApplicationException(string.Format("Input attribute not found (#{0}", 1));
                }
            } catch (Exception) {
                UnloadParameters();
                throw;
            }
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: ilyas032019/EventFrameViewer
        private void AddTrendButton_Click(object sender, EventArgs e)
        {
            if (EFListView.SelectedItems.Count >= 1 && EFAttrView.SelectedItems.Count >= 1)
            {
                for (int i = 0; i < EFListView.SelectedItems.Count; i++)
                {
                    for (int j = 0; j < EFAttrView.SelectedItems.Count; j++)
                    {
                        ListViewItem SelectedEF     = EFListView.SelectedItems[i];
                        ListViewItem SelectedEFattr = EFAttrView.SelectedItems[j];
                        //Get EFName and Attribute Name
                        String EFName     = SelectedEF.SubItems[0].Text;
                        String EFattrName = SelectedEFattr.SubItems[0].Text;
                        String title      = num + "_" + EFName + " : " + EFattrName;

                        //Create GUID for Selected Event Frame
                        Guid   myEFGUID     = Guid.Empty;
                        String myguidstring = SelectedEF.SubItems[4].Text;
                        try { myEFGUID = Guid.Parse(myguidstring); }
                        catch { MessageBox.Show("Cannot convert GUID"); }

                        //Find Selected Event Frame
                        AFEventFrame myEF      = AFEventFrame.FindEventFrame(myAFServer, myEFGUID);
                        AFTime       startTime = myEF.StartTime;
                        AFTime       endTime   = myEF.EndTime;
                        //Set endtime as now for not finishing event frame
                        if (endTime > new AFTime("2099/1/1"))
                        {
                            endTime = DateTime.Now;
                        }
                        AFTimeRange timerange = new AFTimeRange(startTime, endTime);
                        //Find Selected Attribute
                        AFAttribute myEFAttr = myEF.Attributes[SelectedEFattr.Text];

                        DateTime trendstarttime = new DateTime(0);
                        //Check time difference between start time and end time
                        TimeSpan timedif = endTime - startTime;
                        try
                        {
                            AFValues vals = myEFAttr.Data.PlotValues(timerange, 100, null);
                            Int32    chk  = 0;
                            foreach (AFValue val in vals)
                            {
                                //Sometimes System.InvalidOperationException happens.
                                Type t = val.Value.GetType();
                                if (t.FullName != "System.InvalidOperationException")
                                {
                                    if (chk == 0)
                                    {
                                        //Add line to chart1
                                        try
                                        {
                                            //add trend to chart1
                                            chart1.Series.Add(title);
                                            chart1.Series[title].ChartType   = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                                            chart1.Series[title].BorderWidth = 2; // Line width
                                            chart1.Series[title].ToolTip     = "#SERIESNAME\r\nValue : #VALY{N2}\r\nTime : #VALX{N0}";
                                            chart1.ChartAreas[0].AxisX.Title = "Seconds";
                                            //Zoom function
                                            chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
                                            chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.Message);
                                            return;
                                        }
                                        trendstarttime = val.Timestamp.LocalTime;
                                    }
                                    timedif = val.Timestamp.LocalTime - trendstarttime;

                                    //Displaying EnumerationSet value as number
                                    if (t.FullName == "OSIsoft.AF.Asset.AFEnumerationValue")
                                    {
                                        //Errchk = 1;
                                        AFEnumerationValue MyEnumerationValue = (AFEnumerationValue)val.Value;
                                        // last value will be returned as 248. So ignore it
                                        if (MyEnumerationValue.Value != 248)
                                        {
                                            chart1.Series[title].Points.AddXY(timedif.TotalSeconds, MyEnumerationValue.Value.ToString());
                                        }
                                    }
                                    else
                                    {
                                        chart1.Series[title].Points.AddXY(timedif.TotalSeconds, val.Value.ToString());
                                    }
                                    chk = 1;
                                }
                                else
                                {
                                    Errchk = 1;
                                    //Write code for System.InvalidOperationException - Currently ignore it
                                    //AFValue val2 = myEFAttr.GetValue(endTime,null);
                                    //timedif = endTime - startTime;
                                    //chart1.Series[title].Points.AddXY(0, val2.Value.ToString());
                                    //chart1.Series[title].Points.AddXY(timedif.TotalSeconds, val2.Value.ToString());
                                }
                            }
                        }
                        catch
                        {
                            Errchk = 1;
                            //If error happens, write code - Currently ignore it
                            //AFValue val = myEFAttr.GetValue(endTime,null);
                            //chart1.Series[title].Points.AddXY(0, val.Value.ToString());
                            //chart1.Series[title].Points.AddXY(timedif.TotalSeconds, val.Value.ToString());
                        }
                        if (Errchk == 0)
                        {
                            //If there is no error, Set minimum and maximum time
                            chart1.ChartAreas[0].AxisX.Minimum = 0;
                            if (maxtimedif > timedif)
                            {
                                chart1.ChartAreas[0].AxisX.Maximum = maxtimedif.TotalSeconds;
                            }
                            else
                            {
                                chart1.ChartAreas[0].AxisX.Maximum = timedif.TotalSeconds;
                                maxtimedif = timedif;
                            }
                            ++num;
                        }
                        Errchk = 0;
                    }
                }
            }
        }