TrakHound / MTConnect.NET

Fully featured .NET library in C# to build MTConnect Agent, Adapter, and Client Applications. Pre-built Agents with Windows Installers. Support for Windows and Linux. Supports MTConnect Versions up to 2.3. Supports .NET Framework 4.6.1 up to .NET 8
http://www.TrakHound.com
MIT License
96 stars 36 forks source link

ShdrQueueAdapter.AddCondition results in stack overflow #39

Closed scottmwyant closed 6 months ago

scottmwyant commented 1 year ago

Attempting to add a condition by using a ConditionObservationInput object results in a Stack overflow...

using MTConnect.Adapters.Shdr;
using MTConnect.Observations;
using MTConnect.Observations.Input;

    var adapter = new ShdrQueueAdapter("console-adapter");
    adapter.MultilineAssets = true;
    adapter.MultilineDevices = true;
    adapter.AgentConnected += (sender, connectionId) => Console.WriteLine($"Agent Connection (ID = {connectionId}) : Agent Connected");
    adapter.AgentDisconnected += (sender, connectionId) => Console.WriteLine($"Agent Connection (ID = {connectionId}) : Agent Disconnected");
    adapter.PingReceived += (sender, connectionId) => Console.WriteLine($"Agent Connection (ID = {connectionId}) : Agent Ping Received");
    adapter.PongSent += (sender, connectionId) => Console.WriteLine($"Agent Connection (ID = {connectionId}) : Pong Sent to Agent");
    adapter.LineSent += (sender, args) => Console.WriteLine($"Agent Connection (ID = {args.ClientId}) : Line Sent : {args.Message}");
    adapter.Start();

    // var c = new ConditionObservationInput("someId", ConditionLevel.NORMAL, DateTime.Now);
    var c = new ConditionObservationInput("someId");
    adapter.AddCondition(c);

image

PatrickRitchie commented 1 year ago

Try using the "ShdrCondition" class instead of the "ConditionObservationInput" class as there seems to be an issue with using that in the AddCondition() method.

using MTConnect;
using MTConnect.Shdr;

var c = new ShdrCondition("someId");
//var c = new ShdrCondition("someId", ConditionLevel.NORMAL);
//var c = new ShdrCondition("someId", ConditionLevel.NORMAL, UnixDateTime.Now);
adapter.AddCondition(c);

I'm adding better documentation in the "dev" branch and should have a new Release finished this week. Below is a link to the new SHDR readme but note that there are a few changes in the new version (specifically SendCurrent() is now SendChanged()): https://github.com/TrakHound/MTConnect.NET/tree/dev/src/MTConnect.NET-SHDR

scottmwyant commented 1 year ago

Resolved, though there may be another problem, see #41.