Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using jnsoft.ASAP2;
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Windows.Forms;
- namespace jnsoft.MDF.Examples.Writer
- {
- /// <summary>
- /// MDF Writer example.
- ///
- /// - Loading an A2L file
- /// - Recording sample data for all Measurements contained in the specified A2L file
- /// - Recording a 4k raw data sample block.
- ///
- /// Usage: ASAP2MDFWriterExample A2LFile.a2l
- /// </summary>
- class Program
- {
- static int Main(string[] args)
- {
- if (args.Length == 0)
- { // no args -> present usage
- Console.WriteLine($"{Application.ProductName}({Application.ProductVersion})");
- Console.WriteLine("\t Recording a sample MDF recording file containing:");
- Console.WriteLine("\t - All measurements from the specified A2L file");
- Console.WriteLine("\t - A 4k raw data sample block");
- Console.WriteLine($"Usage: {Application.ProductName} A2LFile.a2l");
- return -1;
- }
- try
- {
- // create parser
- using (var a2lParser = new A2LParser())
- {
- // parse specified A2L file
- a2lParser.parse(args[0]);
- // get all measurements from the A2L file
- var measurements = a2lParser.Project.getNode<A2LMODULE>(false).getNodeList<A2LMEASUREMENT>(false);
- // expand measurement arrays
- var measurementList = A2LMEASUREMENT.expandArrays(measurements);
- // Create the MDF writer
- using (var writer = new MDFWriter("ASAP2UnitTest", "jnsoft", "test", "subject", "header comment"))
- {
- // add all measurements to record in the MDF file
- writer.addMeasurements(0, measurementList);
- // add a raw data block
- var rawData = new byte[0x1000];
- var rawDataHandle = writer.addRawData("Raw data", (uint)rawData.Length, "RAW_DATA_BLOCK", "Raw data block");
- // Record start of annotation
- writer.addAnnotation(0, "Start of recording");
- // Create sufficient sample record data
- var data = new byte[writer[0].getRecordSize() - 8];
- // Write 10 sample records
- for (int i = 0; i < 10; ++i)
- {
- // add measurement samples
- writer.addDataEntry(0, i + 1, data);
- // add raw data sample
- writer.addDataEntry(rawDataHandle, i + 1, rawData);
- }
- // Record end of annotation
- writer.addAnnotation(10, "End of recording");
- // Save the MDF file
- System.Diagnostics.Debug.Assert(writer.save($"test.{(writer.Type == MDFType.V4 ? "mf4" : "mdf")}"));
- }
- return 0;
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something failed\n{ex.Message}");
- return -2;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement