Ejemplo n.º 1
0
        /// <summary>
        ///  Common calls of getting Data from AFServer
        /// </summary>
        /// <param name="server_database">String representing the server and database</param>
        /// <param name="AttributeName"> name of the attribute</param>
        /// <param name="MatlabName">variable name for the Matlab Workspace</param>
        /// <param name="start">Start time of data collection.</param>
        /// <param name="end">End time of the data collection.</param>
        /// <param name="afobject"> AF object - AFAttribute, AFEventFrame, or PIPoint</param>
        /// <param name="addToListView"> Whether to add to the Listview (generally true)</param>
        public static void getData(string server_database, string AttributeName, string MatlabName, string start, string end, Object afobject, bool addToListView)
        {
            MatlabName = MatlabAccess.modifyMatlabName(MatlabName);
            LogInput    logInput = null;
            AFValues    Values   = new AFValues();
            AFAttribute attribute;

            object[] vals;
            double[] dbVals;
            double[] timestamps = null;
            int[]    statuses;
            int      baddata;

            //TIME RANGE
            AFTimeRange aftr;

            try { aftr = checkAFTimeRange(start, end); }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw ex;
            }

            /// Get Object
            Type   type       = afobject.GetType();
            string typestring = type.ToString();

            //  LogInput logInput = new LogInput(MatlabName, Element.Name, attribute.Name, path, aftr);
            switch (type.ToString())
            {
            case "OSIsoft.AF.Asset.AFAttribute":
                attribute = (AFAttribute)afobject;
                logInput  = new LogInput(MatlabName, attribute.Element.Name, attribute.Name, attribute.Element.GetPath(), aftr);
                if (attribute.PIPoint == null)         // Constant Value
                {
                    aftr = new AFTimeRange("*", "*");
                    logInput.setAFTimeRange(aftr);
                    Values = attribute.GetValues(aftr, dataPref, null);
                }
                else         // PI Point - Time Matters!!
                {
                    /* Summary: Attribute.GetValues - Important Call!
                     * Parameter Int32 => DataPref
                     *          = 0 :  All Values returned
                     *          < 0 :  Evenly spaced values, including start and end
                     *          > 0 :  # of intervals, for each interval 5 points are given (first, last, high, low, and exceptional)
                     */
                    Values = attribute.GetValues(aftr, dataPref, null);         // FULLY UNDERSTAND THIS !!! Important Call!!!!
                }
                break;

            case "OSIsoft.AF.EventFrame.AFEventFrame":
                AFEventFrame frame = (AFEventFrame)afobject;
                logInput  = new LogInput(MatlabName, frame.Name, frame.Attributes[AttributeName].Name, frame.GetPath(), aftr);
                attribute = frame.Attributes[AttributeName];
                logInput.setAFTimeRange(aftr);
                AFValue val = attribute.GetValue(aftr);
                Values = new AFValues()
                {
                    val
                };
                break;

            case "OSIsoft.AF.PI.PIPoint":
                PIPoint piPoint = (PIPoint)afobject;
                string  path    = piPoint.GetPath();
                logInput = new LogInput(MatlabName, "PI.Point", piPoint.Name, "PI.Point", aftr);
                Values   = piPoint.RecordedValues(aftr, AFBoundaryType.Interpolated, "", true, Int32.MaxValue);
                break;
            }



            //Determine if AFTIME Absolute String
            isAbsoluteTimeString(start, end, logInput);

            logInput.setAttributeGetValueFormat(dataPref);
            logInput.setTimespaceFormat(dataFormat);

            ConvertAFValues.GetValuesArray(Values, false, out vals, out timestamps, out statuses, out baddata);
            try
            {
                MatlabAccess.sendDataToMatlab(MatlabName, AFValuesToArray(vals));

                if (Timestamp)
                {
                    MatlabAccess.sendDataToMatlab(MatlabName + "Time", timestamps);
                }
            }
            catch
            {
                logInput.setServerDatabase(server_database);
                LogSystem.addLogInput(server_database, logInput, addToListView);
                throw new NullReferenceException();
            }

            logInput.setServerDatabase(server_database);
            LogSystem.addLogInput(server_database, logInput, addToListView);
        }