forked from mtconnect/dot_net_sdk
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Setup: Manual Configuration
Trais McAllister edited this page Jan 18, 2023
·
1 revision
Setting up an adapter manually is similar to managing a Dictionary
. All DataItems are managed via their DataItem.Name
in the `Adapter.
In this example, we'll use the TcpAdapter
to get started:
var adapter = new TcpAdapter();
adapter.Start();
// ... manage and publish data items
adapter.Stop();
Next, we'll want to add all of our DataItems manually:
// See Sample, Event, Condition, Message, and TimeSeries data item types
adapter.AddDataItem(new Event("avail")); // EVENT: AVAILABILITY
adapter.AddDataItem(new Event("exec")); // EVENT: EXECUTION
adapter.AddDataItem(new Sample("xpos")); // SAMPLE: PATH_POSITION
adapter.AddDataItem(new Sample("ypos")); // SAMPLE: PATH_POSITION
adapter.AddDataItem(new Sample("zpos")); // SAMPLE: PATH_POSITION
For this example, we'll introduce a loop to randomly update the DataItem values:
var rand = new Random();
string[] executionStates = { "ACTIVE", "READY" };
while (true) {
adapter["avail"].Value = "AVAILABLE";
adapter["exec"].Value = executionStates[rand.Next(0, executionStates.Length)];
adapter["xpos"].Value = rand.NextDouble() * 1000;
adapter["ypos"].Value = rand.NextDouble() * 1000;
adapter["zpos"].Value = rand.NextDouble() * 1000;
System.Threading.Thread.Sleep(1000);
}
Finally, we'll insert the method for publishing the changed values:
var rand = new Random();
string[] executionStates = { "ACTIVE", "READY" };
while (true) {
// ... update the values (shown above)
adapter.Send(DataItemSendTypes.Changed);
System.Threading.Thread.Sleep(1000);
}
var adapter = new TcpAdapter();
adapter.AddDataItem(new Event("avail")); // EVENT: AVAILABILITY
adapter.AddDataItem(new Event("exec")); // EVENT: EXECUTION
adapter.AddDataItem(new Sample("xpos")); // SAMPLE: PATH_POSITION
adapter.AddDataItem(new Sample("ypos")); // SAMPLE: PATH_POSITION
adapter.AddDataItem(new Sample("zpos")); // SAMPLE: PATH_POSITION
adapter.Start();
var rand = new Random();
string[] executionStates = { "ACTIVE", "READY" };
while (true) {
adapter["avail"].Value = "AVAILABLE";
adapter["exec"].Value = executionStates[rand.Next(0, executionStates.Length)];
adapter["xpos"].Value = rand.NextDouble() * 1000;
adapter["ypos"].Value = rand.NextDouble() * 1000;
adapter["zpos"].Value = rand.NextDouble() * 1000;
adapter.Send(DataItemSendTypes.Changed);
System.Threading.Thread.Sleep(1000);
}
adapter.Stop();