-
-
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
5f28c96
commit 992e94f
Showing
5 changed files
with
149 additions
and
5 deletions.
There are no files selected for viewing
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
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
18 changes: 18 additions & 0 deletions
18
clients/MTConnect.NET-Client-MQTT/MTConnect.NET-Client-MQTT.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>MTConnect.NET_Client_MQTT</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\libraries\MTConnect.NET-JSON-cppagent\MTConnect.NET-JSON-cppagent.csproj" /> | ||
<ProjectReference Include="..\..\libraries\MTConnect.NET-JSON\MTConnect.NET-JSON.csproj" /> | ||
<ProjectReference Include="..\..\libraries\MTConnect.NET-MQTT\MTConnect.NET-MQTT.csproj" /> | ||
<ProjectReference Include="..\..\libraries\MTConnect.NET-XML\MTConnect.NET-XML.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,92 @@ | ||
using MTConnect.Formatters; | ||
|
||
namespace MTConnect.Clients.HTTP | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
DocumentClient(); | ||
//EntityClient(); | ||
|
||
Console.ReadLine(); | ||
} | ||
|
||
static void DocumentClient() | ||
{ | ||
var client = new MTConnectMqttClient("localhost", 1883); | ||
client.ClientStarted += (s, args) => { Console.WriteLine("Client Started"); }; | ||
client.ClientStopped += (s, args) => { Console.WriteLine("Client Stopped"); }; | ||
|
||
//client.MessageReceived += (topic, payload) => Console.WriteLine($"Message Received : {topic} : {payload.Length}"); | ||
|
||
client.ProbeReceived += (s, response) => | ||
{ | ||
foreach (var device in response.Devices) Console.WriteLine($"Device Received : {device.Uuid} : {device.Name}"); | ||
}; | ||
|
||
client.CurrentReceived += (s, response) => | ||
{ | ||
foreach (var stream in response.Streams) | ||
{ | ||
foreach (var componentStream in stream.ComponentStreams) | ||
{ | ||
foreach (var observation in componentStream.Observations) | ||
{ | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} : {string.Join(";", observation.Values.Select(o => o.Value))}"); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
client.SampleReceived += (s, response) => | ||
{ | ||
foreach (var stream in response.Streams) | ||
{ | ||
foreach (var componentStream in stream.ComponentStreams) | ||
{ | ||
foreach (var observation in componentStream.Observations) | ||
{ | ||
Console.WriteLine($"Observation Received : {observation.DataItemId} : {string.Join(";", observation.Values.Select(o => o.Value))}"); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
client.AssetsReceived += (s, response) => | ||
{ | ||
foreach (var asset in response.Assets) | ||
{ | ||
var result = EntityFormatter.Format("XML", asset); | ||
if (result.Success) Console.WriteLine(System.Text.Encoding.UTF8.GetString(result.Content)); | ||
} | ||
}; | ||
|
||
client.Start(); | ||
} | ||
|
||
static void EntityClient() | ||
{ | ||
var client = new MTConnectMqttClient("localhost", 1883); | ||
client.ClientStarted += (s, args) => { Console.WriteLine("Client Started"); }; | ||
client.ClientStopped += (s, args) => { Console.WriteLine("Client Stopped"); }; | ||
|
||
client.DeviceReceived += (s, device) => | ||
{ | ||
Console.WriteLine(device.Uuid); | ||
}; | ||
|
||
client.ObservationReceived += (s, observation) => | ||
{ | ||
Console.WriteLine(observation.Uuid); | ||
}; | ||
|
||
client.AssetReceived += (s, asset) => | ||
{ | ||
Console.WriteLine(asset.Uuid); | ||
}; | ||
|
||
client.Start(); | ||
} | ||
} | ||
} |