-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFindAttributesByPathExample.cs
More file actions
42 lines (36 loc) · 1.79 KB
/
FindAttributesByPathExample.cs
File metadata and controls
42 lines (36 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using OSIsoft.AF;
using OSIsoft.AF.Asset;
namespace ExamplesLibrary
{
/// <summary>
/// This example locates an attribute of interest and then get its current value.
/// The target attribute is \\AFServer\NuGreen\NuGreen\Houston\Cracking Process\Equipment\B-210|Process Feedrate.
/// The alternative is traversing down the AF hierarchy, as shown in HierarchyWalkDownExample.
/// </summary>
/// <prerequisite-examples>
/// none
/// </prerequisite-examples>
public class FindAttributesByPathExample : IExample
{
public void Run()
{
string processFeedRate = @"\\<AFSERVER>\NuGreen\NuGreen\Houston\Cracking Process\Equipment\B-210|Process Feedrate";
string waterFlow = @"\\<AFSERVER>\NuGreen\NuGreen\Houston\Cracking Process\Equipment\B-210|Water Flow";
// Directly locate the AFAttribute of interest by passing in the AF path.
// A similar method FindElementsByPath can be used to directly locate elements.
AFKeyedResults<string,AFAttribute> results = AFAttribute.FindAttributesByPath(new[] { processFeedRate, waterFlow }, null);
AFAttribute processFeedRateAttribute = results[processFeedRate];
AFAttribute waterFlowAttribute = results[waterFlow];
AFAttributeList attrList = new AFAttributeList(new[] { processFeedRateAttribute, waterFlowAttribute });
// Make a bulk call to get values.
AFValues values = attrList.GetValue();
foreach (AFValue val in values)
{
Console.WriteLine("Attribute: {0}", val.Attribute);
Console.WriteLine("Timestamp: {0}, Value: {1}", val.Timestamp, val.Value.ToString());
Console.WriteLine();
}
}
}
}