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

Parsing two consecutive conditions failed in streams #32

Closed SergeyGulik closed 2 years ago

SergeyGulik commented 2 years ago

Hi Patrick, Found a problem with two consecutive conditions arriving as part of the stream document. Only the first was successfully parsed. Conditions as I see them now are by default empty nodes and thus no content parsing should be done. Could please pay attention to the test I've added? There is a value override that seems strange for me, maybe it is an earlier introduced bug.

PatrickRitchie commented 2 years ago

Consecutive Conditons in XML Stream

Yes, it looks like you are correct that two consecutive Conditions were not being read correctly and it looks like the commit you added will fix this.

Condition Level

It looks like the Condition Levels read from XML are being added to the internal Values list as PascalCase (ex. Fault, Warning, Normal) but when they are read using the Conditions property in the DeviceStream/ComponentStream they are converted to the Enum which is uppercase. In this scenario, reading as a ConditionObservation, you get uppercase but reading as the abstract Observation using the Values property, you get Pascal Case. The below should fix this issue:

MTConnect.NET-XML > Streams > XmlStreamsResponseDocument > ReadObservationsXml

image

When read as ConditionObservation

public ConditionLevel Level
{
    get => GetValue(ValueKeys.Level).ConvertEnum<ConditionLevel>();
    set => AddValue(ValueKeys.Level, value.ToString());
}

Timestamps

I also noticed some issues with the timestamps when looking at the Test you added. It looks like timestamps were being read from XML as Local time instead of UTC. The below code should fix this:

MTConnect.NET-XML > Streams > XmlStreamsResponseDocument > ReadObservationProperties

image

Updated Release

I will merge the commit you added as well as add the changes I listed here and create a new Release and update the Nuget package.