AnsweredAssumed Answered

Getting Timed Values with AF

Question asked by andrew_Inwood on Mar 2, 2018
Latest reply on Mar 3, 2018 by andrew_Inwood

I'm relatively new to the AF framework, so I think I must be doing something completely wrong (approaching the problem in the wrong way), but I'm not sure what I should be doing instead.  I am trying to get a value of a tag at a certain timestamp.  Here is what I have:

 

public double GetValue(string tagName, DateTime timestamp)
{
//Get the PIPOint
 
PIPoint point = PIPoint.FindPIPoint(DefaultPIServer, tagName);

if (point != null)
{
//Get the timestamp as an AFTimeStamp
 
AFTime requiredTime = new AFTime(timestamp);

//Get the value
 
AFValue value = point.InterpolatedValue(timestamp);

if (value.IsGood)
{
return Convert.ToDouble(value.Value);
}
}
return default(double);
}

Now:  When I pass it the timestamp 02-Mar-18 01:00:00, it retrieves a value, but the value has the timestamp 02-Mar-18 14:00:00.  I have tried passing the datetime (in local time) direct to the function, or trying to set it as the AFTime (as shown above).

 

I am locally in UTC+13. I suspect that the function is being passed as UTC Time and giving me back local time.  When I use:

 

result = PIPoints[tagName].InterpolatedValue(timeStamp.ToUniversalTime());

 

 

I get the right result, but the AFValue timestamp then needs to be converted from Daylight time to Standard time.  Is there an easier way to do this without all these annoying timezone conversions?  Our server is on New Zealand Standard Time, and IO just want to work in New Zealand Standard Time!

 

 

 

Outcomes