ihedvall / mdflib

Implementation of the ASAM MDF data file.
https://ihedvall.github.io/mdflib/
MIT License
57 stars 26 forks source link

Write error #18

Closed Simplxss closed 11 months ago

Simplxss commented 11 months ago

I am writing MdfWriter class for c#(in my fork), but I fould a problem when testing writing file history.

Screenshot 2023-07-20 155537

Following is my code for test.

    var Writer = new MdfWriter(MdfWriterType.Mdf4Basic);
    Writer.Init(FilePath);
    var Header = Writer.Header;
    Header.Author = "Caller";
    Header.Department = "Home Alone";
    Header.Description = "Testing Sample";
    Header.Project = "Mdf3WriteHD";
    Header.StartTime = (ulong)(DateTimeOffset.Now.ToUnixTimeMilliseconds() * 1000000);
    Header.Subject = "PXY";

    var History = Header.CreateFileHistory();
    History.Time = (ulong)(DateTimeOffset.Now.ToUnixTimeMilliseconds() * 1000000);
    History.Description = "Initial stuff";
    History.ToolName = "Unit Test";
    History.ToolVendor = "ACME";
    History.ToolVersion = "2.3";
    History.UserName = "Ducky";

    var dg = Writer.CreateDataGroup();
    var cg = dg.CreateChannelGroup();
    cg.Name = "Test";
    cg.Description = "Test channel group";
    {
        var cn = cg.CreateChannel();
        cn.Name = "Time";
        cn.Description = "Time channel";
        cn.Type = ChannelType.Master;
        cn.Sync= ChannelSyncType.Time;
        cn.DataType = ChannelDataType.FloatLe;
        cn.DataBytes = 4;
        cn.Unit = "s";
        cn.RangeMin = 0;
        cn.RangeMax = int.MaxValue;
    }
    {
        var cn = cg.CreateChannel();
        cn.Name = "UnsignedLe";
        cn.Description = "uint32_t";
        cn.Type = ChannelType.FixedLength;
        cn.DataType = ChannelDataType.UnsignedIntegerLe;
        cn.DataBytes = 4;
    }
   // ...
    {
        var cn = cg.CreateChannel();
        cn.Name = "Time";
        cn.Description = "CANopen Time";
        cn.Type = ChannelType.FixedLength;
        cn.DataType = ChannelDataType.CanOpenTime;
    }

    Writer.InitMeasurement();
    Writer.StartMeasurement((ulong)(DateTimeOffset.Now.ToUnixTimeMilliseconds() * 1000000));
    // ...
    Writer.StopMeasurement((ulong)(DateTimeOffset.Now.ToUnixTimeMilliseconds() * 1000000));
    Writer.FinalizeMeasurement();

System Environment: Windows 10 x64

ihedvall commented 11 months ago

Looks that the XML snippets is invalid. I can test in C++ to check if it's the same problem there.

ihedvall commented 11 months ago

It's confirmed that the same issue in the C++. I will fix the bug in C++.

Simplxss commented 11 months ago

OK, thanks.

ihedvall commented 11 months ago

I have fixed the XML and invalid bit bugs in C++. You need to merge and rebuild the C++ and .NET Library. Please verify in .NET write support.