-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathWriteValuesUsingPIExample.cs
56 lines (45 loc) · 2.07 KB
/
WriteValuesUsingPIExample.cs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using OSIsoft.AF.Asset;
using OSIsoft.AF.Data;
using OSIsoft.AF.PI;
using OSIsoft.AF.Time;
namespace ExamplesLibrary
{
/// <summary>
/// This example demonstrates how to write values to the PI Data Archive using the methods in OSIsoft.AF.PI.
/// An example for numeric and digital tags is given.
/// </summary>
/// <prerequisite-examples>
/// CreatePIPointsExample
/// </prerequisite-examples>
public class WriteValuesUsingPIExample : IExample
{
public void Run()
{
PIServers piServers = new PIServers();
PIServer piServer = piServers["<PISERVER>"];
IList<PIPoint> points = PIPoint.FindPIPoints(piServer, new[] { "sample_floatpoint", "sample_digitalpoint" });
PIPoint floatingPIPoint = points[0];
PIPoint digitalPIPoint = points[1];
AFEnumerationSet digSet = piServer.StateSets["Modes"];
IList<AFValue> valuesToWrite = new List<AFValue>();
for (int i = 0; i < 10; i++)
{
AFTime time = new AFTime(new DateTime(2015, 1, 1, i, 0, 0, DateTimeKind.Local));
AFValue afValueFloat = new AFValue(i, time);
// Associate the AFValue to a PI Point so we know where to write to.
afValueFloat.PIPoint = floatingPIPoint;
AFEnumerationValue digSetValue = i % 2 == 0 ? digSet["Auto"] : digSet["Manual"];
AFValue afValueDigital = new AFValue(digSetValue, time);
afValueDigital.PIPoint = digitalPIPoint;
valuesToWrite.Add(afValueFloat);
valuesToWrite.Add(afValueDigital);
}
// Perform a bulk write. Use a single local call to PI Buffer Subsystem if possible.
// Otherwise, make a single call to the PI Data Archive.
// We use no compression just so we can check all the values are written.
piServer.UpdateValues(valuesToWrite, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible);
}
}
}