-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c41cbbf
commit a08a551
Showing
8 changed files
with
1,212 additions
and
6 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
applications/Clients/MTConnect.NET-Client-Example-01/CppAgentMqttClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using MTConnect.Clients; | ||
using MTConnect.Observations; | ||
|
||
var agentUrl = "localhost"; | ||
|
||
var client = new MTConnectMqtt2Client(agentUrl); | ||
//client.Interval = 100; | ||
//client.Heartbeat = 10000; | ||
//client.ContentType = "application/json"; | ||
//client.DocumentFormat = "json-cppagent"; | ||
client.DeviceReceived += (sender, device) => | ||
{ | ||
Console.WriteLine($"Device Received : {device.Uuid}"); | ||
}; | ||
client.ObservationReceived += (sender, observation) => | ||
{ | ||
switch (observation.Representation) | ||
{ | ||
case MTConnect.Devices.DataItemRepresentation.VALUE: | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} = {observation.GetValue("Result")} @ {observation.Timestamp}"); | ||
break; | ||
|
||
case MTConnect.Devices.DataItemRepresentation.DATA_SET: | ||
if (!observation.IsUnavailable) | ||
{ | ||
var entries = DataSetObservation.GetEntries(observation.Values); | ||
foreach (var entry in entries) | ||
{ | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} : DATA_SET : {entry.Key} = {entry.Value} @ {observation.Timestamp}"); | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} = {observation.GetValue("Result")} @ {observation.Timestamp}"); | ||
} | ||
break; | ||
|
||
case MTConnect.Devices.DataItemRepresentation.TABLE: | ||
if (!observation.IsUnavailable) | ||
{ | ||
var entries = TableObservation.GetEntries(observation.Values); | ||
foreach (var entry in entries) | ||
{ | ||
foreach (var cell in entry.Cells) | ||
{ | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} : TABLE : {entry.Key} : {cell.Key} = {cell.Value} @ {observation.Timestamp}"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} = {observation.GetValue("Result")} @ {observation.Timestamp}"); | ||
} | ||
break; | ||
|
||
case MTConnect.Devices.DataItemRepresentation.TIME_SERIES: | ||
if (!observation.IsUnavailable) | ||
{ | ||
var samples = TimeSeriesObservation.GetSamples(observation.Values).ToList(); | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} : TIME_SERIES : {string.Join(" ", samples)} @ {observation.Timestamp}"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} = {observation.GetValue("Result")} @ {observation.Timestamp}"); | ||
} | ||
break; | ||
} | ||
}; | ||
client.AssetReceived += (sender, asset) => | ||
{ | ||
Console.WriteLine($"Asset Received : {asset.AssetId}"); | ||
}; | ||
client.ClientStarted += (sender, asset) => | ||
{ | ||
Console.WriteLine($"Client Started."); | ||
}; | ||
client.ClientStopped += (sender, asset) => | ||
{ | ||
Console.WriteLine($"Client Stopped."); | ||
}; | ||
|
||
client.Start(); | ||
|
||
Console.ReadLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/MTConnect.NET-JSON-cppagent/Devices/JsonDeviceContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved. | ||
// TrakHound Inc. licenses this file to you under the MIT license. | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
namespace MTConnect.Devices.Json | ||
{ | ||
public class JsonDeviceContainer | ||
{ | ||
[JsonPropertyName("Agent")] | ||
public JsonDevice Agent { get; set; } | ||
|
||
[JsonPropertyName("Device")] | ||
public JsonDevice Device { get; set; } | ||
|
||
|
||
public JsonDeviceContainer() { } | ||
|
||
public JsonDeviceContainer(IDevice device) | ||
{ | ||
if (device != null) | ||
{ | ||
switch (device.Type) | ||
{ | ||
case Devices.Agent.TypeId: | ||
Agent = new JsonDevice(device); | ||
break; | ||
|
||
default: | ||
Device = new JsonDevice(device); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
||
public IDevice ToDevice() | ||
{ | ||
if (Agent != null) | ||
{ | ||
return Agent.ToDevice(); | ||
} | ||
|
||
if (Device != null) | ||
{ | ||
return Device.ToDevice(); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.