-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
66 lines (57 loc) · 2.1 KB
/
Program.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
57
58
59
60
61
62
63
64
65
66
using System;
using System.Threading;
using TitaniumAS.Opc.Client;
using TitaniumAS.Opc.Client.Common;
using TitaniumAS.Opc.Client.Da;
using TitaniumAS.Opc.Client.Da.Browsing;
namespace OPC_test
{
class Program
{
static void Main()
{
Bootstrap.Initialize();
Uri url = UrlBuilder.Build("Matrikon.OPC.Simulation.1");
using (var server = new OpcDaServer(url))
{
// Connect to the server first.
server.Connect();
// Create a group with items.
OpcDaGroup group = server.AddGroup("MyGroup");
group.IsActive = true;
var definition1 = new OpcDaItemDefinition
{
ItemId = "Random.Boolean",
IsActive = true
};
var definition2 = new OpcDaItemDefinition
{
ItemId = "Random.Int1",
IsActive = true
};
var definition3 = new OpcDaItemDefinition
{
ItemId = "Random.Int2",
IsActive = true
};
OpcDaItemDefinition[] definitions = { definition1, definition2, definition3 };
OpcDaItemResult[] results = group.AddItems(definitions);
// Handle adding results.
foreach (OpcDaItemResult result in results)
{
if (result.Error.Failed)
Console.WriteLine("Error adding items: {0}", result.Error);
}
while (true)
{
OpcDaItemValue[] values = group.Read(group.Items, OpcDaDataSource.Device);
Console.WriteLine("Random.Boolean: {0} \n Random.Int1: {1} \n Random.Int2: {2}", values[0].Value, values[1].Value, values[2].Value);
Thread.Sleep(1000);
Console.Clear();
}
/*int count = server.Groups.Count;
Console.WriteLine(count);*/
}
}
}
}