public void Add(string name, object value)
        {
            if (NamedValues.Count % Rows == 0)
            {
                stack.Children.Add(new StackPanel()
                {
                    Margin = new Thickness(0, 0, 20, 0), Orientation = Orientation.Horizontal
                });
                (stack.Children[stack.Children.Count - 1] as StackPanel).Children.Add(new StackPanel());
                (stack.Children[stack.Children.Count - 1] as StackPanel).Children.Add(new StackPanel());
            }

            ((stack.Children[stack.Children.Count - 1] as StackPanel).Children[0] as StackPanel).Children.Add(new Label()
            {
                Content = name, Margin = new Thickness(0, -5, 0, 0)
            });
            ((stack.Children[stack.Children.Count - 1] as StackPanel).Children[1] as StackPanel).Children.Add(new Label()
            {
                Content = value, Margin = new Thickness(0, -5, 0, 0)
            });

            NamedValues.Add(new NamedValue()
            {
                Name = name, Value = value
            });
        }
Пример #2
0
        /// <summary>
        /// 写入单个标签点的历史数据
        /// 这个方法主要用于从csv文件导入历史数据到golden数据库中。从csv读取的数据是字符串型二维数组,因此这里的历史数据入参是字符串型二维数组,而不是List<PValue>
        /// </summary>
        /// <param name="tagname"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int PutArchivedValues(string tagname, string[][] data)
        {
            //注意,只能向数据库第一个有效数据的时间之后,插入历史数据。
            //——如果插入的值得历史时刻在第一个有效值前,则插入不返回错误,但是数据写不进去。
            //准备数据
            PISDK.PIValues pivalues = new PISDK.PIValues(); //新建PIValues,ReadOnly属性为true
            pivalues.ReadOnly = false;                      //只有将PIValues的readonly属性置为false,才能写入。

            //数据点的描述,是一个NamedValues类型。该类型是一个集合。可以添加不同的描述项,并给项设定值
            NamedValues nvatts = new NamedValues();

            nvatts.Add("questionable", true);

            //将数据写入pivalues
            //——只使用第1个值即实时值,第2个值时间。
            int i = 0;

            //try
            //{
            for (i = 0; i < data.Length; i++)
            {
                try
                {
                    //在PI导出的数据中,value有可能是字符串。有时候表示服务器启停,有时候表示“IO timeout”等,这些值都无法转换成数值型,必须跳过。
                    if (data[i] != null && data[i].Length != 0)
                    {
                        pivalues.Add(Convert.ToDateTime(data[i][2]), Convert.ToDouble(data[i][1]), nvatts);
                    }
                }
                catch
                {
                    continue;
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    //将pi的异常PgimDataException记录在_exception中,并以PgimDataException的名称继续抛出异常
            //    this._exception = "写历史数据时,转换数据格式错误!错误行数"+i.ToString();
            //    throw ex;     //将pgim的异常继续向外传递。
            //}

            //使用piPoint.Data.UpdateValues更新点历史数据
            //this._piPoint = new PISDK.PIPoint();
            try
            {
                this._piPoint = this._piServer.PIPoints[tagname];
                PISDKCommon.PIErrors pierror = this._piPoint.Data.UpdateValues(pivalues);
                //处理写入结果
                return(pierror.Count);
            }
            catch (Exception ex)
            {
                //将pi的异常PgimDataException记录在_exception中,并以PgimDataException的名称继续抛出异常
                this._exception = "PI其他未知错误。通常是服务器故障、标签中对应的服务器名称不正确导致!";
                throw ex;     //将pgim的异常继续向外传递。
                return(-1);
            }
        }
Пример #3
0
        private bool TryAddAsNamedValue(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as SymbolNamedValue;

            if (symbol == null)
            {
                return(false);
            }

            NamedValues.Add(symbolName, symbol);

            return(true);
        }
Пример #4
0
        private bool TryAddAsConstant(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacConstant;

            if (symbol == null)
            {
                return(false);
            }

            Constants.Add(symbolName, symbol);

            NamedValues.Add(symbolName, symbol);

            return(true);
        }
Пример #5
0
        private bool TryAddAsFrameBasisVector(string symbolName, LanguageSymbol langSymbol)
        {
            var symbol = langSymbol as GMacFrameBasisVector;

            if (symbol == null)
            {
                return(false);
            }

            FrameBasisVectors.Add(symbolName, symbol);

            NamedValues.Add(symbolName, symbol);

            return(true);
        }
Пример #6
0
        public NamedValues <RegexValue <ZValue> > GetRegexValues()
        {
            if (_match == null)
            {
                throw new PBException("can't get values, no match found");
            }
            NamedValues <RegexValue <ZValue> > values = new NamedValues <RegexValue <ZValue> >();

            if (_match.Success)
            {
                foreach (RegexValueDefinition value in _regexValues.NamedValuesDefinitions.Values)
                {
                    values.Add(value.Name, value.GetRegexValue(_match));
                }
            }
            return(values);
        }
Пример #7
0
        public void ExecuteMetadataRefresh(object state)
        {
            OnStatusMessage("Beginning metadata refresh...");

            try
            {
                base.RefreshMetadata();

                if (InputMeasurementKeys != null && InputMeasurementKeys.Any())
                {
                    IPIPoints2 pts2 = (IPIPoints2)m_server.PIPoints;
                    //NamedValues edits = new NamedValues();
                    //PIErrors errors = new PIErrors();
                    PointList piPoints;
                    DataTable dtMeasurements = DataSource.Tables["ActiveMeasurements"];
                    DataRow[] rows;
                    foreach (MeasurementKey key in InputMeasurementKeys)
                    {
                        rows = dtMeasurements.Select(string.Format("SIGNALID='{0}'", key.SignalID));

                        if (rows.Any())
                        {
                            string tagname = rows[0]["POINTTAG"].ToString();
                            if (!String.IsNullOrWhiteSpace(rows[0]["ALTERNATETAG"].ToString()))
                                tagname = rows[0]["ALTERNATETAG"].ToString();

                            piPoints = m_server.GetPoints(string.Format("EXDESC='{0}'", rows[0]["SIGNALID"].ToString()));

                            if (piPoints.Count == 0)
                            {
                                m_server.PIPoints.Add(rows[0]["POINTTAG"].ToString(), m_piPointClass, PointTypeConstants.pttypFloat32);
                            }
                            else if (piPoints[1].Name != rows[0]["POINTTAG"].ToString())
                            {
                                pts2.Rename(piPoints[1].Name, rows[0]["POINTTAG"].ToString());
                            }
                            else
                            {
                                foreach (PIPoint pt in piPoints)
                                {
                                    if (pt.Name != rows[0]["POINTTAG"].ToString())
                                        pts2.Rename(pt.Name, rows[0]["POINTTAG"].ToString());
                                }
                            }

                            PIErrors errors = new PIErrors();
                            NamedValues edits = new NamedValues();
                            NamedValues edit = new NamedValues();
                            edit.Add("pointsource", m_piPointSource);
                            edit.Add("Descriptor", rows[0]["SIGNALREFERENCE"].ToString());
                            edit.Add("exdesc", rows[0]["SIGNALID"].ToString());
                            edit.Add("sourcetag", rows[0]["POINTTAG"].ToString());

                            if (dtMeasurements.Columns.Contains("ENGINEERINGUNITS")) // engineering units is a new field for this view -- handle the case that its not there
                                edit.Add("engunits", rows[0]["ENGINEERINGUNITS"].ToString());

                            edits.Add(rows[0]["POINTTAG"].ToString(), edit);
                            pts2.EditTags(edits, out errors, null);

                            if (errors.Count > 0)
                                OnStatusMessage(errors[0].Description);
                        }
                    }
                }
                else
                {
                    OnStatusMessage("PI Historian is not configured with any input measurements. Therefore, metadata sync will not do work.");
                }
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                OnProcessException(ex);
            }
            finally
            {
                m_metadataRefreshComplete.Set();
            }

            OnStatusMessage("Completed metadata refresh successfully.");
        }