Beispiel #1
0
        // Import to AF
        /// <summary>
        ///  Gets value from Matlab and writes it to AF.
        /// </summary>
        /// <remarks> Will not write, if the Attribute is read-only. A Matlab Variable Name must be input.</remarks>
        /// <param name="path"> The path to the Element to search with.</param>
        /// <param name="workspaceVariableName">The variable name in Matlab being used.</param>
        /// <param name="AFName">The attribute name in AF being written to.</param>
        public void ImportToAF(string path, string workspaceVariableName, string AFName)
        {
            object val = null;
            double dbVal;

            //LOGIC: A variable name must be entered.
            try
            {
                MatlabAccess.GetWorkspaceData(workspaceVariableName, "base", out val);
            }
            catch
            {
                mainForm.Status("Couldn't find the variable in the Matlab Workspace");
            }

            List <string> searchPaths = new List <string>()
            {
                path
            };
            AFKeyedResults <string, AFElement> results = AFElement.FindElementsByPath(searchPaths, null);
            AFElement   Element   = results[path];
            AFAttribute Attribute = Element.Attributes[AFName];

            double.TryParse(val.ToString(), out dbVal);
            try
            {
                AFAccess.writeToAF(Element, Attribute, dbVal);
            }
            catch
            {
                mainForm.Status("Cannot Write to this Attribute");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Exports the Event Frame Data, using the AFViewControl to select an EventFrame and EventFrame Attribute.
        /// </summary>
        private void exportEventFrameData()
        {
            string name = avcEventAttributes.AFSelection.ToString();

            if (name != null)
            {
                string srv_db = "'" + _curServer + "'_'" + _curDatabase + "'";

                AFAccess.getEventFrameData(srv_db, name, getUserVariableName(name), (AFEventFrame)avcEventFrames.AFSelection, true);
            }
        }
Beispiel #3
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; }
 }
Beispiel #4
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; }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
 // Data Preferences
 /// <summary>
 ///  Passes the Data Preferences from the MainForm to the AFAccess.
 /// </summary>
 /// <param name="timestamp"> true: exports the timestamp to Matlab.</param>
 /// <param name="datapref"> Integer for Attribute.GetValues; 0(raw), negative(sampling), positive(profiled sampling)</param>
 /// <param name="format"> String representation of the Data Preferences. </param>
 public void currentDataPrefChanges(bool timestamp, int datapref, string format)
 {
     AFAccess.setDataPrefs(timestamp, datapref, format);
 }
Beispiel #7
0
        // Import Saved Log
        /// <summary>
        /// Imports a saved file into Matlab.
        /// </summary>
        /// <param name="path"> The path to the importe File.</param>
        /// <returns></returns>
        public string[] importLog(string path)
        {
            try
            {
                string[] lines = LogSystem.ImportLog(path);
                foreach (string line in lines)
                {
                    if (line != string.Empty)
                    {
                        string[] info = Regex.Split(line, @"=");
                        mainForm.Status("Importing: " + info[1] + " as " + info[0]);

                        if (info.Length == 2)
                        {
                            _curServer   = info[0];
                            _curDatabase = info[1];
                        }
                        else if (info.Length == 6) //Absolute Time
                        {
                            if (info[5] != string.Empty)
                            {
                                mainForm.dataPrefDialog.setupDataPreferences(info[5]);
                            }
                            string srv_db = "'" + _curServer + "'_'" + _curDatabase + "'";
                            if (info[2] == "PI.Point")
                            {
                                getPIData(info[1], _curServer, info[0], info[3], info[4], true);
                            }
                            else
                            {
                                getAFData(srv_db, info[1], info[0], info[2], info[3], info[4], true);
                            }
                        }
                        else // Dates
                        {
                            string[] time = Regex.Split(info[3], @"-");
                            if (info[4] != string.Empty)
                            {
                                mainForm.dataPrefDialog.setupDataPreferences(info[4]);
                            }
                            string srv_db = "'" + _curServer + "'_'" + _curDatabase + "'";
                            if (info[2] == "PI.Point")
                            {
                                getPIData(info[1], _curServer, info[0], time[0], time[1], true);
                            }
                            else
                            {
                                try
                                {
                                    List <string> paths = new List <string>()
                                    {
                                        info[2]
                                    };
                                    AFKeyedResults <string, AFEventFrame> frames = AFEventFrame.FindEventFramesByPath(paths, null);

                                    int          i     = frames.Count;
                                    AFEventFrame frame = frames[paths[0]];
                                    AFAccess.getEventFrameData(srv_db, info[1], info[0], frame, true);
                                }
                                catch
                                {
                                    getAFData(srv_db, info[1], info[0], info[2], time[0], time[1], true);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                mainForm.Status("ERROR: Invalid import file. Please choose a different file.");
            }
            return(new string[] { _curServer, _curDatabase });
        }