MTConnect.NET-HTTP implements the HTTP protocol for use with the MTConnect.NET library. Supports MTConnect Versions up to 2.5. Supports .NET Framework 4.6.1 up to .NET 9
$ dotnet add package MTConnect.NET-HTTPThese client classes use the Http REST Api that is described in MTConnect Standard.
The MTConnectHttpClient class is the primary class to use when wanting to implement the full MTConnect REST protocol. This class handles an initial Probe request to gather capabilities of the Agent, a Current request to read the initial values, and a Sample request (at the specified Interval) to read successive values.
Class initialization is straightforward in that specifiying the BaseUrl (the URL of the Agent) is all that is required. Then call the Start() method to start the request sequence.
using MTConnect.Clients;
var baseUrl = "localhost:5000";
var client = new MTConnectHttpClient(baseUrl);
client.Interval = 500;
client.Start();
using MTConnect.Clients;
var baseUrl = "localhost:5000";
var deviceName = "OKUMA-Lathe";
var client = new MTConnectHttpClient(baseUrl, deviceName);
client.Interval = 500;
client.Start();
using MTConnect.Clients;
var hostname = "localhost";
var port = 5000;
var client = new MTConnectHttpClient(hostname, port);
client.Interval = 500;
client.Start();
using MTConnect.Clients;
var hostname = "localhost";
var port = 5000;
var deviceName = "OKUMA.Lathe";
var client = new MTConnectHttpClient(hostname, port, deviceName);
client.Interval = 500;
client.Start();
Id - A unique Identifier used to indentify this instance of the MTConnectClient class
Authority - The authority portion consists of the DNS name or IP address associated with an Agent
Device - If present, specifies that only the Equipment Metadata for the piece of equipment represented by the name or uuid will be published
DocumentFormat - Gets or Sets the Document Format to use (ex. XML, JSON, etc.)
Interval - Gets or Sets the Interval in Milliseconds for the Sample Stream
Timeout - Gets or Sets the connection timeout for the request
Heartbeat - Gets or Sets the MTConnect Agent Heartbeat for the request
RetryInterval - Gets or Sets the Interval in Milliseconds that the Client will attempt to reconnect if the connection fails
MaximumSampleCount - Gets or Sets the Maximum Number of Samples returned per interval from the Sample Stream
ContentEncodings - Gets or Sets the List of Encodings (ex. gzip, br, deflate) to pass to the Accept-Encoding HTTP Header
ContentType - Gets or Sets the Content-type (or MIME-type) to pass to the Accept HTTP Header
LastInstanceId - Gets the Last Instance ID read from the MTConnect Agent
LastSequence - Gets the Last Sequence read from the MTConnect Agent
LastResponse - Gets the Unix Timestamp (in Milliseconds) since the last response from the MTConnect Agent
CurrentOnly - Gets or Sets whether the stream requests a Current (true) or a Sample (false)
var baseUrl = "localhost:5000";
var deviceName = "OKUMA-Lathe";
var client = new MTConnectHttpClient(baseUrl, deviceName);
client.OnProbeReceived += (sender, document) =>
{
foreach (var device in document.Devices)
{
// Device
Console.WriteLine(device.Id);
// All DataItems (traverse the entire Device model)
foreach (var dataItem in device.GetDataItems())
{
Console.WriteLine(dataItem.IdPath);
}
// All Components (traverse the entire Device model)
foreach (var component in device.GetComponents())
{
Console.WriteLine(component.IdPath);
}
// All Compositions (traverse the entire Device model)
foreach (var composition in device.GetCompositions())
{
Console.WriteLine(composition.IdPath);
}
}
};
client.Start();var baseUrl = "localhost:5000";
var deviceName = "OKUMA-Lathe";
var client = new MTConnectHttpClient(baseUrl, deviceName);
client.OnCurrentReceived += (sender, document) =>
{
foreach (var deviceStream in document.Streams)
{
// DeviceStream
Console.WriteLine(deviceStream.Name);
// Component Streams
foreach (var componentStream in deviceStream.ComponentStreams)
{
Console.WriteLine(componentStream.Name);
// DataItems (Samples, Events, and Conditions)
foreach (var observation in componentStream.Observations)
{
Console.WriteLine(observation.DataItemId);
}
}
}
};
client.Start();var baseUrl = "localhost:5000";
var deviceName = "OKUMA-Lathe";
var client = new MTConnectHttpClient(baseUrl, deviceName);
client.Interval = 500;
client.OnSampleReceived += (sender, document) =>
{
foreach (var deviceStream in document.Streams)
{
// DeviceStream
Console.WriteLine(deviceStream.Name);
// Component Streams
foreach (var componentStream in deviceStream.ComponentStreams)
{
Console.WriteLine(componentStream.Name);
// DataItems (Samples, Events, and Conditions)
foreach (var observation in componentStream.Observations)
{
Console.WriteLine(observation.DataItemId);
}
}
}
};
client.Start();var baseUrl = "localhost:5000";
var deviceName = "OKUMA-Lathe";
var client = new MTConnectHttpClient(baseUrl, deviceName);
client.Interval = 500;
client.OnAssetsReceived += (sender, document) =>
{
foreach (var asset in document.Assets)
{
// Print AssetId to the Console
Console.WriteLine(asset.AssetId);
}
};
client.Start();The MTConnectHttpProbeClient class is used to send a Probe request and return an MTConnectDevices Response Document.
var baseUrl = "localhost:5000";
var deviceName = "OKUMA.Lathe";
var client = new MTConnectHttpProbeClient(baseUrl, deviceName);
var document = client.Get();
foreach (var device in document.Devices)
{
// Device
Console.WriteLine(device.Id);
// All DataItems (traverse the entire Device model)
foreach (var dataItem in device.GetDataItems())
{
Console.WriteLine(dataItem.IdPath);
}
// All Components (traverse the entire Device model)
foreach (var component in device.GetComponents())
{
Console.WriteLine(component.IdPath);
}
// All Compositions (traverse the entire Device model)
foreach (var composition in device.GetCompositions())
{
Console.WriteLine(composition.IdPath);
}
}The MTConnectHttpCurrentClient class is used to send a Current request and return an MTConnectStreams Response Document.
var baseUrl = "localhost:5000";
var deviceName = "OKUMA.Lathe";
var client = new MTConnectHttpCurrentClient(baseUrl, deviceName);
var document = client.Get();
foreach (var deviceStream in document.Streams)
{
// Device
Console.WriteLine(deviceStream.Name);
// Component Streams
foreach (var componentStream in deviceStream.ComponentStreams)
{
Console.WriteLine(componentStream.Name);
// DataItems (Samples, Events, and Conditions)
foreach (var observation in componentStream.Observations)
{
Console.WriteLine(observation.DataItemId);
}
}
}The MTConnectHttpSampleClient class is used to send a Sample request and return an MTConnectStreams Response Document.
var baseUrl = "localhost:5000";
var deviceName = "OKUMA.Lathe";
var fromSequence = 150;
var toSequence = 250;
var client = new MTConnectHttpSampleClient(baseUrl, deviceName, fromSequence, toSequence);
var document = client.Get();
foreach (var deviceStream in document.Streams)
{
// Device
Console.WriteLine(deviceStream.Name);
// Component Streams
foreach (var componentStream in deviceStream.ComponentStreams)
{
Console.WriteLine(componentStream.Name);
// DataItems (Samples, Events, and Conditions)
foreach (var observation in componentStream.Observations)
{
Console.WriteLine(observation.DataItemId);
}
}
}The MTConnectHttpAssetClient class is used to send an Assets request and return an MTConnectAssets Response Document.
var baseUrl = "localhost:5000";
var deviceName = "OKUMA.Lathe";
var count = 5
var client = new MTConnectHttpAssetClient(baseUrl, deviceName, count);
var document = client.Get();
foreach (var asset in document.Assets)
{
// Print AssetId to the Console
Console.WriteLine(asset.AssetId);
}