To get all available samples using a specific time filter, use the GetSamples
method. The library delivers a PagedResult
that contains a list of Sample
. The GetSamples
method accepts the GUID of the object, the attribute ID, and a TimeFilter
object to filter the response.
Library method name |
GetSamples
|
---|---|
Description | To get available trends samples |
Method signature |
PagedResult<Sample> GetSamples(Guid objectId, int attributeId, TimeFilter filter);
|
Method input parameters |
|
Return value | A PagedResult of Sample . |
The following .NET C# code is an example of a successful get trends response:
Guid trendedObjectId = client.GetObjectIdentifier("Win2016-VM2:vNAE2343701/Field Bus MSTP1.VAV-08.ZN-T");
// Get attributes where trend extension is configured
List<Attribute> trendedAttributes = client.Trends.GetTrendedAttributes(trendedObjectId);
int attributeId = trendedAttributes[0].Id;
TimeFilter timeFilter = new TimeFilter
{
StartTime = new DateTime(2020, 5, 12),
EndTime = new DateTime(2020, 5, 13)
};
PagedResult<Sample> samplesPager = client.Trends.GetSamples(trendedObjectId, attributeId, timeFilter);
// Prints the number of records fetched and paging information
Console.WriteLine("Total:" + samplesPager.Total);
Console.WriteLine("Current page:" + samplesPager.CurrentPage);
Console.WriteLine("Page size:" + samplesPager.PageSize);
Console.WriteLine("Pages:" + samplesPager.PageCount);
/*
Total:145
Current page:1
Page size:100
Pages:2
*/
Sample firstSample = samplesPager.Items.FirstOrDefault();
Console.WriteLine(firstSample);
/*
{
"Value": 82.0,
"Unit": "deg F",
"Timestamp": "2020-05-12T05:00:00Z",
"IsReliable": true
}
*/