// GET: Home public ActionResult Index() { PIServer piServer = new PIServers().DefaultPIServer; piServer.Connect(); IEnumerable<PIPoint> piPointList = PIPoint.FindPIPoints(piServer, "*"); PIPointList pointList = new PIPointList(); pointList.AddRange(piPointList); AFListResults<PIPoint, AFValue> results = pointList.EndOfStream(); IEnumerable<PIPointData> pointListData = results.Select(m => new PIPointData(m.PIPoint.Name, m.Value, m.Timestamp.LocalTime, m.PIPoint.ID)); return View(pointListData); }
private void btnGetData_Click(object sender, EventArgs e) { _dt.Rows.Clear(); PIPointList piPointList = new PIPointList(); piPointList.AddRange(piPointTagSearchPage1.PIPoints); AFValues afValues = new AFValues(); foreach (var piPoint in piPointList) { afValues.AddRange(piPoint.RecordedValues(new AFTimeRange(new AFTime(DateTime.SpecifyKind(dthInicio.Value, DateTimeKind.Local)), new AFTime(DateTime.SpecifyKind(dthFim.Value, DateTimeKind.Local))), AFBoundaryType.Inside, string.Empty, false)); } foreach (var afValue in afValues) { _dt.Rows.Add(afValue.PIPoint.Name, (DateTime)afValue.Timestamp.LocalTime, afValue.Value, afValue.PIPoint.GetAttribute(PICommonPointAttributes.EngineeringUnits), afValue.GetAnnotation(), false, string.Empty); } dataGrid.DataSource = _dt; }
private void getSnapshot(object obj) { List <PIPoint> p = obj as List <PIPoint>; SetDataGridCallback _dataGridCallback = new SetDataGridCallback(SetDataTable); PIDataPipe pipe = new PIDataPipe(AFDataPipeType.Archive); pipe.AddSignups(p); //_dt.Rows.Clear(); _dt = new DataTable(); _dt.Columns.Add("Tag", typeof(string)); _dt.Columns.Add("Timestamp", typeof(DateTime)); _dt.Columns.Add("Value", typeof(object)); _dt.Columns.Add("UOM", typeof(string)); _dt.Columns.Add("Annotation", typeof(string)); _dt.Columns.Add("CheckBox", typeof(bool)); _dt.Columns.Add("Message", typeof(string)); PIPointList piPointList = new PIPointList(); piPointList.AddRange(p); AFValues afValues = new AFValues(); foreach (var piPoint in piPointList) { afValues.Add(piPoint.CurrentValue()); } foreach (var afValue in afValues) { _dt.Rows.Add(afValue.PIPoint.Name, (DateTime)afValue.Timestamp.LocalTime, afValue.Value, afValue.PIPoint.GetAttribute(PICommonPointAttributes.EngineeringUnits), afValue.GetAnnotation(), false, string.Empty); } this.Invoke(_dataGridCallback, _dt); while (chkShowSnapshot.Checked == true) { AFListResults <PIPoint, AFDataPipeEvent> pipeConstants = pipe.GetUpdateEvents(5000); foreach (AFDataPipeEvent pipeEvent in pipeConstants) { foreach (DataRow row in _dt.Rows) { if (row["Tag"] == pipeEvent.Value.PIPoint.Name) { row["Timestamp"] = pipeEvent.Value.Timestamp.LocalTime; row["Value"] = pipeEvent.Value.Value; row["UOM"] = pipeEvent.Value.PIPoint.GetAttribute(PICommonPointAttributes.EngineeringUnits); row["Annotation"] = pipeEvent.Value.GetAnnotation(); } } } if (this.dataGrid.InvokeRequired) { this.Invoke(_dataGridCallback, _dt); } else { dataGrid.DataSource = _dt; dataGrid.Refresh(); } } ; pipe.Close(); pipe.Dispose(); }
static void Main(string[] args) { Console.WriteLine(new string('~', 45)); if (GlobalConfig.Debug) { Console.WriteLine($"Main thread: {Thread.CurrentThread.ManagedThreadId}"); } if (GlobalConfig.Debug) { Console.WriteLine($"Args length: {args.Length}"); } var commandsList = new List <string>() { "snap", "sign,a", "sign,s", "sign,sa", "sign,as", "sign,t", "arclist", "interp", "plot", "summaries", "update", "annotate", "delete" }; var pointsList = new PIPointList(); var command = String.Empty; var startTime = String.Empty; var endTime = String.Empty; var serverName = String.Empty; var addlparam1 = string.Empty; var tagMasks = new string[] { }; var times = new string[] { }; var summaryDuration = new AFTimeSpan(TimeSpan.FromMinutes(10)); var st = new AFTime(); var et = new AFTime(); PIServer myServer; try { var AppplicationArgs = new ParseArgs(args); if (!AppplicationArgs.CheckHelpVersionOrEmpty()) { return; } if (!AppplicationArgs.CheckCommandExists(commandsList, out command)) { return; } if (!AppplicationArgs.GetTagNames(out tagMasks)) { return; } if (!AppplicationArgs.GetAddlParams(command, ref times, ref startTime, ref endTime, ref addlparam1, ref serverName)) { return; } } catch (Exception ex) { ParseArgs.PrintHelp(ex.Message); return; } #region Connect Server, Verify Times and Points if (!String.IsNullOrEmpty(startTime) && !String.IsNullOrEmpty(endTime)) { if (!AFTime.TryParse(startTime, out st)) { ParseArgs.PrintHelp($"Invalid start time {startTime}"); return; } if (!AFTime.TryParse(endTime, out et)) { ParseArgs.PrintHelp($"Invalid end time {endTime}"); return; } if (st == et) //same time or min case (from initialization) { ParseArgs.PrintHelp("Incorrect or same time interval specified"); return; } } try { PIServers myServers = new PIServers(); if (string.IsNullOrEmpty(serverName)) { if (GlobalConfig.Debug) { Console.WriteLine("Attempting connection to default server ..."); } myServer = myServers.DefaultPIServer; } else if (myServers.Contains(serverName)) { if (GlobalConfig.Debug) { Console.WriteLine($"Attempting connection to {serverName} server ..."); } myServer = myServers[serverName]; } else { ParseArgs.PrintHelp($"Server {serverName} not found in KST"); return; } if (myServer != null) { myServer.ConnectionInfo.Preference = AFConnectionPreference.Any; myServer.Connect(); Console.WriteLine($"Connected to {myServer.Name} as {myServer.CurrentUserIdentityString}"); } } catch (Exception ex) { ParseArgs.PrintHelp("Server Connection error: " + ex.Message); return; } try { //foreach (var n in tagMasks) //{ // if (PIPoint.TryFindPIPoint(myServer, n, out PIPoint p)) // { // if (!pointsList.Contains(p)) pointsList.Add(p); // else Console.WriteLine($"Duplicate point {p.Name}"); // } // else // { // Console.WriteLine($"Point {n} not found"); // } //} pointsList.AddRange(PIPoint.FindPIPoints(myServer, new List <string>(tagMasks), null)); if (pointsList.Count == 0) { ParseArgs.PrintHelp("No valid PI Points"); myServer.Disconnect(); return; } } catch (Exception ex) { ParseArgs.PrintHelp("Tagmask error " + ex.Message); return; } #endregion //Handle KeyPress event from the user Console.CancelKeyPress += (sender, eventArgs) => { if (GlobalConfig.Debug) { Console.WriteLine(Thread.CurrentThread.ManagedThreadId); } Console.WriteLine(); Console.WriteLine("Program termination received from user ..."); if (command == "sign,s" || command == "sign,as" || command == "sign,sa" || command == "sign,a" || command == "sign,t") { GlobalConfig.CancelSignups = true; Thread.Sleep(Convert.ToInt32(GlobalConfig.PipeCheckFreq * 1.2)); } else { if (myServer != null) { myServer.Disconnect(); } Console.WriteLine(new string('~', 45)); } }; var Exec = new ExecuteCommand(); if (GlobalConfig.Debug) { Console.WriteLine($"Command executing: {command}"); } Exec.Execute(command, pointsList, st, et, summaryDuration, times, addlparam1, myServer); bool isexec = true; if (myServer != null) { myServer.Disconnect(); if (GlobalConfig.Debug) { Console.WriteLine($"Disconnecting from {myServer.Name}"); } } if (!isexec) { Console.WriteLine(new string('~', 45)); } }
public void PIDataPipeTimeSeriesTest(PIPointType piPointType, object[] eventValues) { Contract.Requires(eventValues != null); const string PointName = "PIDataPipeTests_PIPoint"; AFDatabase db = AFFixture.AFDatabase; PIServer piServer = PIFixture.PIServer; var piDataPipe = new PIDataPipe(AFDataPipeType.TimeSeries); var piPointList = new PIPointList(); var now = AFTime.NowInWholeSeconds; try { Output.WriteLine("Create the Future PI Points with Zero Compression and specified PI Point type."); PIFixture.DeletePIPoints(PointName + "*", Output); var testPIPoints = PIFixture.CreatePIPoints(PointName + "###", eventValues.Length, new Dictionary <string, object> { { PICommonPointAttributes.PointType, piPointType }, { PICommonPointAttributes.ExceptionDeviation, 0 }, { PICommonPointAttributes.ExceptionMaximum, 0 }, { PICommonPointAttributes.Compressing, 0 }, { PICommonPointAttributes.DigitalSetName, "Phases" }, { PICommonPointAttributes.Future, true }, }); Assert.True(testPIPoints.Count() == eventValues.Length, $"Unable to create all the test PI Points."); piPointList.AddRange(testPIPoints); // Add the PI Point as sign up to the PIDataPipe. Output.WriteLine($"Sign up all PI Points with PIDataPipe."); var afErrors = piDataPipe.AddSignups(piPointList); var prefixErrorMessage = "Adding sign ups to the PIDataPipe was unsuccessful."; Assert.True(afErrors == null, userMessage: afErrors?.Errors.Aggregate(prefixErrorMessage, (msg, error) => msg += $" PI Point: [{error.Key.Name}] Error: [{error.Value.Message}] ")); // Write one data value to each PI Point. var expectedAFValues = new AFValues(); for (int i = 0; i < eventValues.Length; i++) { AFValue afValue = null; var timestamp = now + TimeSpan.FromMinutes(i - eventValues.Length); // Special Handling of Input Data for Digital and Timestamp switch (piPointType) { case PIPointType.Digital: afValue = new AFValue(new AFEnumerationValue("Phases", (int)eventValues[i]), timestamp); break; case PIPointType.Timestamp: afValue = new AFValue(new AFTime(eventValues[i], now), timestamp); break; default: afValue = new AFValue(eventValues[i], timestamp); break; } Output.WriteLine($"Writing Value [{eventValues[i]}] with Timestamp [{timestamp}] to PI Point [{piPointList[i].Name}]."); piPointList[i].UpdateValue(afValue, AFUpdateOption.InsertNoCompression); // If writing digital states, we need to save the corresponding value for verification. // Since we are using Phases, 0 ~ Phase1, 1 ~ Phase2, etc. if (piPointType == PIPointType.Digital) { int input = (int)eventValues[i]; afValue = new AFValue(new AFEnumerationValue($"Phase{input + 1}", input), timestamp); } afValue.PIPoint = piPointList[i]; expectedAFValues.Add(afValue); } // Retry assert to retrieve expected Update Events from the PIDataPipe var actualAFValues = new AFValues(); Output.WriteLine($"Reading Events from the PI DataPipe."); AssertEventually.True(() => { var updateEvents = piDataPipe.GetUpdateEvents(eventValues.Length); prefixErrorMessage = "Retrieving Update Events from the PIDataPipe was unsuccessful."; Assert.False(updateEvents.HasErrors, userMessage: updateEvents.Errors?.Aggregate(prefixErrorMessage, (msg, error) => msg += $" PI Point: [{error.Key.Name}] Error: [{error.Value.Message}] ")); actualAFValues.AddRange(updateEvents.Results.Select(update => update.Value)); if (actualAFValues.Count >= expectedAFValues.Count) { // Verify that all expected update events are received from the PIDataPipe Assert.True(expectedAFValues.Count == actualAFValues.Count, "PIDataPipe returned more events than expected. " + $"Expected Count: {expectedAFValues.Count}, Actual Count: {actualAFValues.Count}."); return(true); } return(false); }, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(0.5), "Unable to retrieve events within the time frame."); // Verify all received events. Output.WriteLine($"Verifying all {actualAFValues.Count} events from the PI DataPipe."); for (int i = 0; i < actualAFValues.Count; i++) { // Special handling of Output events for Timestamp if (piPointType == PIPointType.Timestamp) { actualAFValues[i].Value = new AFTime(actualAFValues[i].Value, now); } AFFixture.CheckAFValue(actualAFValues[i], expectedAFValues[i]); Assert.True(object.Equals(actualAFValues[i].PIPoint, expectedAFValues[i].PIPoint), $"Unexpected PI Point Association. Expected: [{expectedAFValues[i].PIPoint}], Actual: [{actualAFValues[i].PIPoint}]."); } // Remove all sign ups from the PIDataPipe Output.WriteLine($"Remove all PI Point sign ups from PIDataPipe."); afErrors = piDataPipe.RemoveSignups(piPointList); prefixErrorMessage = "Removing sign ups to the PIDataPipe was unsuccessful."; Assert.True(afErrors == null, userMessage: afErrors?.Errors.Aggregate(prefixErrorMessage, (msg, error) => msg += $" PI Point: [{error.Key.Name}] Error: [{error.Value.Message}] ")); // Write dummy values to the PI Points and confirm PI DataPipe receives none. Output.WriteLine($"Write dummy values to the PI Points."); for (int i = 0; i < eventValues.Length; i++) { piPointList[i].UpdateValue(new AFValue(eventValues[i], now), AFUpdateOption.InsertNoCompression); } Output.WriteLine($"Verify no events are received by the PIDataPipe."); var noEvents = piDataPipe.GetUpdateEvents(eventValues.Length); prefixErrorMessage = "Retrieving Update Events from the PIDataPipe was unsuccessful."; Assert.False(noEvents.HasErrors, userMessage: noEvents.Errors?.Aggregate(prefixErrorMessage, (msg, error) => msg += $" PI Point: [{error.Key.Name}] Error: [{error.Value.Message}] ")); Assert.True(noEvents.Count == 0, "PIDataPipe received events even after removing all sign ups."); } finally { piDataPipe.RemoveSignups(piPointList); piDataPipe.Dispose(); PIFixture.DeletePIPoints(PointName + "*", Output); } }