modifyMatlabName() public static method

Make UserInput Matlab-Friendly and Check for Unique Variable Name 1) UserInput-MatlabFriendly - Remove punctuation and numbers at start 2) Check Unique Variables - check Matlab workspace and Log System
public static modifyMatlabName ( string varName ) : string
varName string Either user-input name or attribute name
return string
Ejemplo n.º 1
0
 /// <summary>
 ///  Accesses the AFServer to get data.
 /// </summary>
 /// <param name="server_database"> The string of the server and database 'server'-'database'</param>
 /// <param name="attName"> Name of the Attribute.</param>
 /// <param name="MatlabName"> Variable name to be used in Matlab workspace.</param>
 /// <param name="searchPath"> The path to the Element.</param>
 /// <param name="start">The time at which data will start being imported from.</param>
 /// <param name="end">The time when data will stop being imported.</param>
 /// <param name="edit"> true: Adds the log input into the LogSystem (generally true)</param>
 /// <returns></returns>
 public void getAFData(string server_database, string attName, string MatlabName, string searchPath, string start, string end, bool edit)
 {
     MatlabName = MatlabAccess.modifyMatlabName(MatlabName);
     if (MatlabName == string.Empty)
     {
         return;
     }
     try
     {
         AFAccess.getAFData(server_database, attName, MatlabName, searchPath, start, end, edit);
         mainForm.Status("Data sent for " + attName);
         return;
     }
     catch { checkMatlab(true); mainForm.Status("ERROR: Data not sent for  " + attName); return; }
 }
Ejemplo n.º 2
0
        // Export Data
        /// <summary>
        /// Get the Data from PIServer using AFSDK.
        /// </summary>
        /// <param name="point"> The name of the PIPoint.</param>
        /// <param name="server"> The PIServer</param>
        /// <param name="MatlabName"> The name of the variable to be used for Matlab.</param>
        /// <param name="start"> The time to start taking data from.</param>
        /// <param name="end">The time to stop taking data from.</param>
        /// <param name="edit"> true: Adds the log to the LogSystem (generally true)</param>
        /// <returns></returns>
        public void getPIData(string point, string server, string MatlabName, string start, string end, bool edit)
        {
            string name = MatlabAccess.modifyMatlabName(MatlabName);

            if (name == string.Empty)
            {
                return;
            }
            try
            {
                AFAccess.getPIData(name, server, point, start, end, edit);
                mainForm.Status("Data sent for " + point);
                return;
            }
            catch { checkMatlab(true); mainForm.Status("ERROR: Data not sent for  " + point); return; }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  Resulting Action of editting the List View.
        ///  1) Edit the List Item
        ///  2) Re-log the item
        ///  3) Edit the Matlab workspace.
        /// </summary>
        /// <param name="name"> The new variable name. (or the same)</param>
        /// <param name="start"> The new start time. (or the same)</param>
        /// <param name="end"> The new end time. (or the same)</param>
        /// <param name="previous"></param>
        public void EditLog(string name, string start, string end, LogInput previous)
        {
            MatlabAccess.removeMatlabVariable(previous.getKeyVariableName());
            if (previous.getKeyVariableName() != name)
            {
                name = MatlabAccess.modifyMatlabName(name);
            }
            if (name == string.Empty)
            {
                name = previous.getKeyVariableName();
            }
            string attName = previous.getAttribute();
            string path    = previous.getPath();
            string elem    = previous.getElement();

            //EDIT LIST VIEW
            if (AFAccess.isAbsoluteTimeString(start, end, previous))
            {
                lv_LogDialog.SelectedItems[0].SubItems[3].Text = start + " = " + end;
                lv_LogDialog.SelectedItems[0].Text             = name;
            }
            else
            {
                AFTimeRange range = new AFTimeRange(start, end);
                lv_LogDialog.SelectedItems[0].SubItems[3].Text = range.ToString();
                lv_LogDialog.SelectedItems[0].Text             = name;
            }


            //EDIT ACTUAL LOG
            LogSystem.removeLogInput(previous.getKeyVariableName(), previous.getServerDatabase());

            //Workspace Edit - remove variable, getNewData
            if (path == "PI.Point")
            {
                string[] info = Regex.Split(previous.getServerDatabase(), "'");
                control.getPIData(attName, info[1], name, start, end, false);
            }
            else
            {
                control.getAFData(previous.getServerDatabase(), attName, name, path, start, end, false);
            }
        }
Ejemplo n.º 4
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);
        }