-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.cs
61 lines (49 loc) · 1.73 KB
/
Module.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
using MTConnect.Agents;
using MTConnect.Devices;
using MTConnect.Observations;
namespace MTCAgentTest;
public class Module : MTConnectInputAgentModule
{
public const string ConfigurationTypeId = "datasource"; // This must match the module section in the 'agent.config.yaml' file
public const string DefaultId = "DataSource Module"; // The ID is mainly just used for logging.
private Sink _sink;
public Module(IMTConnectAgentBroker agent, Sink sink) : base(agent)
{
_sink = sink;
Id = DefaultId;
}
protected override void OnRead()
{
foreach (var message in _sink.Inbox)
{
var value1 = $"{((List<ObservationValue>)message.Value)[0].Value} TEST TEST";
if (message.Key == "avail")
{
ProcessMessage("Device[Name=device1]/Availability[Category=Event]", value1);
}
if (message.Key == "execution")
{
ProcessMessage("Device[Name=device1]/Controller/Path/Execution[Category=Event]", value1);
}
if (message.Key == "Xload")
{
ProcessMessage("Device[Name=device1]/Axes/Linear[Name=X]/Load[Category=Sample]", value1);
}
}
_sink.Inbox.Clear();
}
private void ProcessMessage(string path, object value)
{
var devices = Agent.GetDevices().ToDictionary(o => o.Name, o => (Device)o);
var (wasModified, device, dataItem) =
Builder.Build(
devices,
path,
path);
if (wasModified)
{
Agent.AddDevice(device);
}
Agent.AddObservation(device.Uuid, dataItem.Id, value);
}
}