Exemple #1
0
        List <PIAttributesClass> GetPiData(string tagName)
        {
            if (string.IsNullOrEmpty(tagName))
            {
                tagName = "*";
            }
            List <PIAttributesClass> attributes = new List <PIAttributesClass>();

            if (tagName.Trim() != "*")
            {
                PISDK.PISDK sdk = new PISDK.PISDK();
                //Server srv = sdk.Servers["mus-as-126.corp.pdo.om"];
                //srv.Open("UID=upoa;PWD=upoa");
                string piServer      = string.IsNullOrEmpty(ConfigurationSettings.AppSettings["PIServer"]) ? "mus-as-126.corp.pdo.om" : ConfigurationSettings.AppSettings["PIServer"];
                string piCredentials = string.IsNullOrEmpty(ConfigurationSettings.AppSettings["PICredentials"]) ? "UID=upoa;PWD=upoa" : ConfigurationSettings.AppSettings["PICredentials"];
                Server srv           = sdk.Servers[piServer];
                srv.Open(piCredentials);
                PIPoints  myPoints = srv.PIPoints;
                PointList list     = srv.GetPoints("tag = '" + tagName + "'");
                int       count    = list.Count > 100 ? 100 : list.Count;
                for (int i = 1; i <= count; i++)
                {
                    PIData data = list[i].Data;
                    try
                    {
                        attributes.Add(new PIAttributesClass {
                            Descriptor = (list[i].PointAttributes["Descriptor"].Value).ToString(), EngUnits = (list[i].PointAttributes["EngUnits"].Value).ToString(), Instrumenttag = (list[i].PointAttributes["instrumenttag"].Value).ToString(), PITag = (list[i].PointAttributes["Tag"].Value).ToString(), PointType = (list[i].PointAttributes["pointtype"].Value).ToString()
                        });
                    }
                    catch (Exception ex)
                    { }
                }
            }
            return(attributes);
        }
Exemple #2
0
        /// <summary>
        /// 获取极值
        /// </summary>
        /// <param name="tagName">查询条件</param>
        /// <param name="startTime">起始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="nv"></param>
        /// <param name="atc"></param>
        /// <param name="qs">极值的类型,年份,月份,天</param>
        /// <returns></returns>
        public virtual StringBuilder GetSummary(string tagName, DateTime startTime, DateTime endTime, out NamedValues nv, ArchiveSummaryTypeConstants atc, QueryStyle qs)
        {
            PointList pLst = null;

            if (this.server == null)
            {
                //log4net.ILog log = log4net.LogManager.GetLogger(this.GetType());
                //log.Debug("PIServer未初始化");
                logs.writelog("PIServer未初始化");
                throw new Exception("piserver未初始化。");
            }
            StringBuilder sb = new StringBuilder();

            try
            {
                PIData  pData  = null;
                PIValue pValue = null;
                switch (qs)
                {
                case QueryStyle.Year:
                    startTime = DateTime.Parse(startTime.Year.ToString() + "-01-01 00:00:00");
                    endTime   = DateTime.Parse(endTime.Year.ToString() + "12-31 23:59:59");
                    break;

                case QueryStyle.Month:
                    startTime = DateTime.Parse(startTime.Year.ToString() + "-" + startTime.Month.ToString() + "-01 00:00:00");
                    endTime   = DateTime.Parse(endTime.Year.ToString() + "-" + endTime.Month.ToString() + "-31 23:59:59");
                    break;

                default:
                    break;
                }
                PITime ptStart = new PITime();
                ptStart.LocalDate = startTime;
                PITime ptEnd = new PITime();
                ptEnd.LocalDate = endTime;
                if (!this.server.Connected)
                {
                    this.server.Open(this.piConnectionString);
                }
                nv   = null;
                pLst = this.server.GetPoints(tagName, null); //此时pLst中不会存在数据,也就是客户端现在还没有数据
                foreach (PIPoint point in pLst)
                {
                    pData  = point.Data;                                                                                         //取数据
                    pValue = pData.Summary(ptStart, ptEnd, atc, CalculationBasisConstants.cbTimeWeighted, new PIAsynchStatus()); //取极值数据
                    sb.AppendFormat(point.Name + "|" + pValue.TimeStamp.LocalDate.ToString() + "|" + pValue.Value.ToString() + "!");
                }
                sb.Remove(sb.Length - 1, 1);
            }
            catch (Exception ex)
            {
                //log4net.ILog log = log4net.LogManager.GetLogger(this.GetType());
                //log.Error(ex);
                logs.writelog("获取极值发生错误:" + ex);
                throw new Exception("获取极值发生错误:" + ex.Message);
            }
            return(sb);
        }
Exemple #3
0
        List <Pi> getPiData(string tagName, DateTime StartDate, DateTime EndDate, out string unit)
        {
            PISDK.PISDK sdk           = new PISDK.PISDK();
            string      piServer      = string.IsNullOrEmpty(ConfigurationSettings.AppSettings["PIServer"]) ? "mus-as-126.corp.pdo.om" : ConfigurationSettings.AppSettings["PIServer"];
            string      piCredentials = string.IsNullOrEmpty(ConfigurationSettings.AppSettings["PICredentials"]) ? "UID=upoa;PWD=upoa" : ConfigurationSettings.AppSettings["PICredentials"];
            Server      srv           = sdk.Servers[piServer];

            srv.Open(piCredentials);
            string nameConcat = "";
            int    i          = 0;

            PISDK.PIPoints myPoints = srv.PIPoints;
            PointList      list     = srv.GetPoints("tag = '*" + tagName + "*'");
            int            count    = list.Count;
            PIData         data     = list[1].Data;

            unit = list[1].PointAttributes["EngUnits"].Value.ToString();
            PIValues        values;
            List <string>   stringValues = new List <string>();
            List <DateTime> timeValues   = new List <DateTime>();
            List <Pi>       piData       = new List <Pi>();

            try
            {
                values = data.RecordedValues(StartDate, EndDate);
                foreach (PIValue value in values)
                {
                    try
                    {
                        if (value.Value.GetType().IsCOMObject)
                        {
                            stringValues.Add((value.Value as DigitalState).Name.ToString());
                            PITimeServer.PITime pt = value.TimeStamp;
                        }
                        else
                        {
                            stringValues.Add((value.Value).ToString());
                            Pi p = new Pi();
                            p.time  = value.TimeStamp.LocalDate;
                            p.value = Convert.ToString(value.Value);
                            p.tag   = tagName;
                            piData.Add(p);
                        }
                    }
                    catch (Exception ex)
                    { //throw ex;
                    }
                }
            }
            catch (Exception ex)
            { }
            return(piData);
        }
        List <Pi> getPiData(string tagName, DateTime StartDate, DateTime EndDate)
        {
            ////DateTime startTime = DateTime.Now.AddSeconds(-1);
            ////DateTime endTime = DateTime.Now;
            ////TimeSpan span = new TimeSpan(0, 5, 0);
            PISDK.PISDK sdk = new PISDK.PISDK();
            //PISDK.Server srv = sdk.Servers["mus-as-126.corp.pdo.om"];
            //srv.Open("UID=upoa;PWD=upoa");
            string piServer      = string.IsNullOrEmpty(ConfigurationSettings.AppSettings["PIServer"]) ? "mus-as-126.corp.pdo.om" : ConfigurationSettings.AppSettings["PIServer"];
            string piCredentials = string.IsNullOrEmpty(ConfigurationSettings.AppSettings["PICredentials"]) ? "UID=upoa;PWD=upoa" : ConfigurationSettings.AppSettings["PICredentials"];
            Server srv           = sdk.Servers[piServer];

            srv.Open(piCredentials);
            string nameConcat = "";
            int    i          = 0;

            PISDK.PIPoints  myPoints = srv.PIPoints;
            PointList       list     = srv.GetPoints("tag = '*" + tagName + "*'");
            int             count    = list.Count;
            PIData          data     = list[1].Data;
            PIValues        values;
            List <string>   stringValues = new List <string>();
            List <DateTime> timeValues   = new List <DateTime>();
            List <Pi>       piData       = new List <Pi>();

            try
            {
                ////DateTime DateTimeStart = new DateTime();
                ////DateTimeStart = Convert.ToDateTime(StartDate);
                ////DateTime DateTimeEnd = new DateTime();
                ////DateTimeEnd = Convert.ToDateTime(EndDate);
                ////if (!string.IsNullOrEmpty(Request.Form["txtStartDate"]))
                ////{
                ////    TimeSpan timeSpan = new TimeSpan(int.Parse(ddlHoursStart.SelectedValue), int.Parse(ddlMinutesStart.SelectedValue), 0);
                ////    DateTimeStart.Add(timeSpan);
                ////    DateTimeEnd.AddHours(int.Parse(ddlHoursEnd.SelectedValue));
                ////    DateTimeEnd.AddMinutes(int.Parse(ddlMinutesEnd.SelectedValue));
                ////}
                values = data.RecordedValues(StartDate, EndDate);
                foreach (PIValue value in values)
                {
                    try
                    {
                        if (value.Value.GetType().IsCOMObject)
                        {
                            stringValues.Add((value.Value as DigitalState).Name.ToString());
                            PITimeServer.PITime pt = value.TimeStamp;
                        }
                        else
                        {
                            stringValues.Add((value.Value).ToString());
                            Pi p = new Pi();
                            p.time  = value.TimeStamp.LocalDate;
                            p.value = Convert.ToString(value.Value);
                            p.tag   = tagName;
                            piData.Add(p);
                        }
                    }
                    catch (Exception ex)
                    { //throw ex;
                    }
                }
            }
            catch (Exception ex)
            { }
            return(piData);
        }