jagadeesh.macherla

PI Eventing - How to get last changed value

Discussion created by jagadeesh.macherla on Mar 15, 2011
Latest reply on Mar 17, 2011 by charlie@osisoft.com

Hi Team

 

As I raised a concern in my earlier thread that I have implemented OnNewValueChanges event for eventpipe to notify for value changes, how can i get the delta change for value, in other words, i need to get the difference between last value and new value. I have seen the property LastValueSent in PIData object but its implemented in SDK.

 

Han Yong(OSIsoft Vcampus Member) suggested two ways of acheving the same:

  1. PIData.RecordedValuesByCount
  2. PIData.ArcValue

 

 

Following parameters are recieved
TagName : sinusoid
Connected to default PI Server
Created EventPipe from ListData.... Waiting for new events
 Previous Value :85.66788,96.36205 Date is :3/15/2011 4:28:59 PM. Event: sinusoid, New Value : 85.82043
 Previous Value :85.66788,96.36205 Date is :3/15/2011 4:28:59 PM. Event: sinusoid, New Value : 85.66788
 Previous Value :84.58118,96.36205 Date is :3/15/2011 4:32:30 PM. Event: sinusoid, New Value : 84.73842
 Previous Value :84.58118,96.36205 Date is :3/15/2011 4:32:30 PM. Event: sinusoid, New Value : 84.58118
 Previous Value :83.46222,96.36205 Date is :3/15/2011 4:36:01 PM. Event: sinusoid, New Value : 83.624
 Previous Value :83.46222,96.36205 Date is :3/15/2011 4:36:01 PM. Event: sinusoid, New Value 83.46222

 

There are two things to note:

  1. For same timestamp, it is returning two events.
  2. If I am not wrong, as per Han's post, the new value generated in previous timestamp should be the Previous value in next timestamp, which is not happening in this case.

The code snippet for the event generation is as follows:

 

 

 

 

 

 

 

 I also tried PIData.ArcValue method but again the new value does not matches with previous value for next timestamp.

 

private void myEvents_OnNewValue()
{
     try
     {
          Array EVP = myPipe.TakeAll();
          foreach (Object _obj in EVP)
          {
               EO = _obj as PIEventObject;
               _ptValue = (PointValue)EO.EventData;
               
               //PIValue pivalue = _ptValue.PIPoint.Data.ArcValue(DateTime.Now, RetrievalTypeConstants.rtBefore, null);
               PIValues piValues = _ptValue.PIPoint.Data.RecordedValuesByCount(System.DateTime.Now, 2, DirectionConstants.dReverse, BoundaryTypeConstants.btInside, "", FilteredViewConstants.fvRemoveFiltered, null);

               _value = _ptValue.PIValue;

                if (_value.Value is DigitalState)
               {
                  Console.WriteLine("\n Previous Value :" + piValues[1].Value + "," + piValues[2].Value + " Date is :" + EO.ReceivedTime.LocalDate + ". Event: " + _ptValue.PIPoint.Name + ", New Value : " + ((DigitalState)_value.Value).Name);
               }
               else
               {
                    Console.WriteLine("\n Previous Value :" + piValues[1].Value + "," + piValues[2].Value + " Date is :" + EO.ReceivedTime.LocalDate + ". Event: " + _ptValue.PIPoint.Name + ", New Value :  " + _value.Value.ToString());
               }
          }
     }
     catch (Exception ex)
     {
          Console.WriteLine(ex.Message.ToString());
     }
}

 

 

Please assist me on this.

 

Jagadeesh

Outcomes