Giter VIP home page Giter VIP logo

mklimczuk / mtconnect.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from trakhound/mtconnect.net

0.0 0.0 0.0 1.48 MB

MTConnect.NET is a .NET library for the MTConnect® protocol for machine tool data collection. Uses the .NET XmlSerializer to parse and easy to use functions for requesting data from MTConnect Agents. Updated to support up to MTConnect v1.5.

License: Apache License 2.0

C# 100.00%

mtconnect.net's Introduction

MTConnect.NET Logo

NuGet

MTConnect.NET is a .NET library for the MTConnect® protocol for machine tool data collection. Uses the .NET XmlSerializer to parse and easy to use functions for requesting data from MTConnect Agents. Updated to support up to MTConnect v1.5.

Features

  • Easy to use client classes
  • Full MTConnect document responses as class objects
  • Intellisense using text directly from the MTConnect Standard
  • Simple parsing using built in XmlSerializer

Installation

Nuget

PM> Install-Package MTConnect.NET

http://www.nuget.org/packages/MTConnect.NET/

Examples

MTConnectClient

The MTConnectClient class handles the entire request structure for a typical data collection application using MTConnect. First a Probe request is made, then a Current request, then a stream is opened for any new Sample data. The class will continue to run until the Stop() method is called and will handle errors internally.

using MTConnectDevices = MTConnect.MTConnectDevices;
using MTConnectStreams = MTConnect.MTConnectStreams;
using MTConnect.Clients;

MTConnectClient client;

void Start()
{
  // The base address for the MTConnect Agent
  string baseUrl = "http://agent.mtconnect.org";

  // Create a new MTConnectClient using the baseUrl
  client = new MTConnectClient(baseUrl);

  // Subscribe to the Event handlers to receive the MTConnect documents
  client.ProbeReceived += DevicesSuccessful;
  client.CurrentReceived += StreamsSuccessful;
  client.SampleReceived += StreamsSuccessful;

  // Start the MTConnectClient
  client.Start();
}

void Stop()
{
  client.Stop();
}

// --- Event Handlers ---

void DevicesSuccessful(MTConnectDevices.Document document)
{
  foreach (var device in document.Devices)
  {
     var dataItems = device.GetDataItems();
     foreach (var dataItem in dataItems) Console.WriteLine(dataItem.Id + " : " + dataItem.Name);
  }
}

void StreamsSuccessful(MTConnectStreams.Document document)
{
  foreach (var deviceStream in document.DeviceStreams)
  {
     foreach (var dataItem in deviceStream.DataItems) Console.WriteLine(dataItem.DataItemId + " = " + dataItem.CDATA);
  }
}

MTConnect Requests

The Probe, Current, and Sample requests return the appropriate MTConnect document object. Requests can be sent either synchronously or asynchronously and errors are returned as an MTConnectError document. Request constructors have multiple overloads to make configuration easier and to keep your code clean.

Probe

// The base address for the MTConnect Agent
string baseUrl = "http://agent.mtconnect.org";

// Execute the Probe request and get an MTConnectDevices.Document object back
var probe = new Probe(baseUrl).Execute();

// Execute the Probe request asynchronously and return the MTConnectDevices.Document using the event handler
var probe = new Probe(baseUrl);
probe.Successful += ProbeSuccess;
probe.ExecuteAsync();

Current

// The base address for the MTConnect Agent
string baseUrl = "http://74.203.109.245:5001";

// Execute the Current request and get an MTConnectStreams.Document object back
var current = new Current(baseUrl).Execute();

Sample

// The base address for the MTConnect Agent
string baseUrl = "http://agent.mtconnect.org";

// Execute the Sample request from sequence 200 to 500 and get an MTConnectStreams.Document object back
var sample = new Sample(baseUrl, 200, 500).Execute();

Documents

The Document classes use the same structure as laid out in the raw MTConnect XML file and allow you to easily list or search the DataItems by Component or DataItem ID using Linq.

MTConnectDevices.Document

// Find DataItem by ID
var avail = document.Devices[0].GetDataItems().Find(o => o.Id == "avail");

// Find DataItem by Type
var estop = document.Devices[0].GetDataItems().Find(o => o.Type == "EMERGENCY_STOP");

// Find the first Controller component
var controller = document.Devices[0].GetComponents().Find(o => o.GetType() == typeof(MTConnectDevices.Components.Controller));

// Find DataItem by Type in the first Controller/Path component
var program = document.Devices[0].GetComponents().Find(o => o.GetType() == typeof(MTConnectDevices.Components.Path)).DataItems.Find(o => o.Type == "PROGRAM");

// Find all of the Line Types in each Controller/Path component
foreach (var path in document.Devices[0].GetComponents().FindAll(o => o.GetType() == typeof(MTConnectDevices.Components.Path)))
{
  var line = path.DataItems.Find(o => o.Type == "LINE");
}

MTConnectStreams.Document

// Find DataItem by ID and write value to console
var avail = document.DeviceStreams[0].DataItems.Find(o => o.DataItemId == "avail");
if (avail != null) Console.WriteLine(avail.CDATA);

// Find DataItem by Type
var estop = document.DeviceStreams[0].DataItems.Find(o => o.Type == "EMERGENCY_STOP");

// Find the a ComponentStream by the ComponentId
var cn1 = document.DeviceStreams[0].ComponentStreams.Find(o => o.ComponentId == "cn1");

// Find a Condition by Id and write both the Condition and CDATA to console
var htemp = document.DeviceStreams[0].Conditions.Find(o => o.DataItemId == "htemp");
if (htemp != null) Console.WriteLine(htemp.ConditionValue + " : " + htemp.CDATA);

License

This library is licensed under the Apache 2.0 License

mtconnect.net's People

Contributors

patrickritchie avatar mklimczuk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.