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); }
float GetCurrentValue(string tagname) { float currentvalue = 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); PISDK.PIPoints myPoints = srv.PIPoints; try { PIValue value = myPoints[tagname].Data.Snapshot; currentvalue = value.Value; } catch (Exception ex) { } return(currentvalue); }
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); }