Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Windows.Forms;
- namespace jnsoft.Diagnose.ODX.Examples
- {
- /// <summary>
- /// Sample console application.
- ///
- /// Demonstrates parsing, changing, (re)writing an ODX file and
- /// printing some information from the object model.
- ///
- /// Usage: ASAP2ODXExample ODXFile.odx
- /// </summary>
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length == 0)
- { // no args -> present usage
- Console.WriteLine($"{Application.ProductName}({Application.ProductVersion})");
- Console.WriteLine("\t Parse the specified ODX file");
- Console.WriteLine("\t and do some example output of ODX contents");
- Console.WriteLine($"Usage: {Application.ProductName} ODXFile.odx");
- return;
- }
- if (!File.Exists(args[0]))
- { // file does not exist
- Console.WriteLine($"File '{args[0]}' does not exist!");
- return;
- }
- var prevColor = Console.ForegroundColor;
- try
- {
- var odxFile = ODXFile.open(args[0]);
- var dlc = odxFile.ODX.DIAG_LAYER_CONTAINER;
- if (null != dlc)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- var DTCs = odxFile.ODX.getDTCs();
- Console.WriteLine($"ODX model version: {odxFile.ODX.MODEL_VERSION}, defined trouble codes: {DTCs.Count}");
- if (dlc.PROTOCOLS != null)
- foreach (var protocol in dlc.PROTOCOLS)
- Console.WriteLine($"Defined protocol: {protocol} ({protocol.TYPE}, Baudrate: {(int)protocol.Baudrate / 1000} kBit)");
- if (dlc.BASE_VARIANTS != null)
- foreach (var bv in dlc.BASE_VARIANTS)
- Console.WriteLine($"ECU Base variant: {bv}(Supported services: {(bv.FunctClasses.Count)})");
- if (dlc.ECU_VARIANTS != null)
- foreach (var ecu in dlc.ECU_VARIANTS)
- Console.WriteLine($"\tECU variant: {ecu} (form Base Variant: {ecu.Parent}, Defined services: {ecu.DiagServices.Count})");
- }
- else
- Console.WriteLine("ODX parsed successfully, but no diag layer container defined...");
- // change something in the ODX model
- odxFile.ODX.MODEL_VERSION = "2.0.2";
- // Save the file
- odxFile.save(Path.ChangeExtension(odxFile.SourceFile, ".out.odx"));
- Console.WriteLine($"Successfully saved the file as {Path.GetFileName(odxFile.SourceFile)}");
- }
- catch (Exception ex)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("File '{0}' seems not to be an ODX file, caught exception:\n{1}\nStacktrace\n{2}"
- , args[0], ex.Message, ex.StackTrace
- );
- }
- finally
- {
- Console.ForegroundColor = prevColor;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement