Skip to content

Commit

Permalink
Updated client example projects
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Dec 9, 2023
1 parent 5f28c96 commit 992e94f
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 5 deletions.
11 changes: 11 additions & 0 deletions MTConnect.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MTConnect.NET-AgentModule-MqttBroker", "agent\Modules\MTConnect.NET-AgentModule-MqttBroker\MTConnect.NET-AgentModule-MqttBroker.csproj", "{93EC3021-51BC-48D2-8AB2-F7F427952DDD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MTConnect.NET-Client-MQTT", "clients\MTConnect.NET-Client-MQTT\MTConnect.NET-Client-MQTT.csproj", "{2844E2F1-8CC0-437B-A730-9045A25971F6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -377,6 +379,14 @@ Global
{93EC3021-51BC-48D2-8AB2-F7F427952DDD}.Package|Any CPU.Build.0 = Package|Any CPU
{93EC3021-51BC-48D2-8AB2-F7F427952DDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93EC3021-51BC-48D2-8AB2-F7F427952DDD}.Release|Any CPU.Build.0 = Release|Any CPU
{2844E2F1-8CC0-437B-A730-9045A25971F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2844E2F1-8CC0-437B-A730-9045A25971F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2844E2F1-8CC0-437B-A730-9045A25971F6}.Docker|Any CPU.ActiveCfg = Debug|Any CPU
{2844E2F1-8CC0-437B-A730-9045A25971F6}.Docker|Any CPU.Build.0 = Debug|Any CPU
{2844E2F1-8CC0-437B-A730-9045A25971F6}.Package|Any CPU.ActiveCfg = Debug|Any CPU
{2844E2F1-8CC0-437B-A730-9045A25971F6}.Package|Any CPU.Build.0 = Debug|Any CPU
{2844E2F1-8CC0-437B-A730-9045A25971F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2844E2F1-8CC0-437B-A730-9045A25971F6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -418,6 +428,7 @@ Global
{3B6E6874-ADB2-4C59-9E65-C13693466920} = {4558F2F3-D5B7-49DE-AC9C-8E778C4D3585}
{619557F6-A8D5-4995-9D96-0E3174221FC6} = {4558F2F3-D5B7-49DE-AC9C-8E778C4D3585}
{93EC3021-51BC-48D2-8AB2-F7F427952DDD} = {0F01D2F5-0CFA-4DAE-A0FD-5733D291F6FB}
{2844E2F1-8CC0-437B-A730-9045A25971F6} = {4558F2F3-D5B7-49DE-AC9C-8E778C4D3585}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC13D3AD-18BF-4695-AB2A-087EF0885B20}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

<ItemGroup>
<ProjectReference Include="..\..\libraries\MTConnect.NET-HTTP\MTConnect.NET-HTTP.csproj" />
<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-XML\MTConnect.NET-XML.csproj" />
</ItemGroup>

Expand Down
31 changes: 26 additions & 5 deletions clients/MTConnect.NET-Client-HTTP/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,49 @@ internal class Program
static void Main(string[] args)
{
DocumentClient();
EntityClient();
//EntityClient();

Console.ReadLine();
}

static void DocumentClient()
{
var client = new MTConnectHttpClient("localhost", 5000);
var client = new MTConnectHttpClient("localhost", 5001);
client.Interval = 100;
client.ClientStarted += (s, args) => { Console.WriteLine("Client Started"); };
client.ClientStopped += (s, args) => { Console.WriteLine("Client Stopped"); };

client.ProbeReceived += (s, response) =>
{
Console.WriteLine(response.Devices.Count());
foreach (var device in response.Devices) Console.WriteLine($"Device Received : {device.Uuid} : {device.Name}");
};

client.CurrentReceived += (s, response) =>
{
Console.WriteLine(response.Streams.Count());
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) =>
{
Console.WriteLine(response.Streams.Count());
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) =>
Expand Down
18 changes: 18 additions & 0 deletions clients/MTConnect.NET-Client-MQTT/MTConnect.NET-Client-MQTT.csproj
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>
92 changes: 92 additions & 0 deletions clients/MTConnect.NET-Client-MQTT/Program.cs
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();
}
}
}

0 comments on commit 992e94f

Please sign in to comment.