//The below is basically ripped straight out of example ediabaslib code private EdiabasNet StartEdiabas() { EdiabasNet ediabas = new EdiabasNet(); EdInterfaceBase edInterface; edInterface = new EdInterfaceObd(); ediabas.EdInterfaceClass = edInterface; ediabas.ProgressJobFunc = ProgressJobFunc; ediabas.ErrorRaisedFunc = ErrorRaisedFunc; ((EdInterfaceObd)edInterface).ComPort = Global.Port; ediabas.ArgBinary = null; ediabas.ArgBinaryStd = null; ediabas.ResultsRequests = string.Empty; ediabas.SetConfigProperty("EcuPath", Global.ecuPath); ediabas.ResultsRequests = string.Empty; try { ediabas.ResolveSgbdFile(Global.sgbd); } catch (Exception ex2) { System.Diagnostics.Debug.WriteLine("ResolveSgbdFile failed: " + EdiabasNet.GetExceptionText(ex2)); } return(ediabas); }
static int Main(string[] args) { string cfgString = null; string sgbdFile = null; string comPort = null; string outFile = null; string ifhName = string.Empty; bool appendFile = false; bool storeResults = false; bool printAllTypes = false; List <string> formatList = new List <string>(); List <string> jobNames = new List <string>(); bool showHelp = false; var p = new OptionSet() { { "cfg=", "config string.", v => cfgString = v }, { "s|sgbd=", "sgbd file.", v => sgbdFile = v }, { "p|port=", "COM port.", v => comPort = v }, { "o|out=", "output file name.", v => outFile = v }, { "a|append", "append output file.", v => appendFile = v != null }, { "ifh=", "interface handler.", v => ifhName = v }, { "store", "store results.", v => storeResults = v != null }, { "c|compare", "compare output.", v => _compareOutput = v != null }, { "alltypes", "print all value types.", v => printAllTypes = v != null }, { "f|format=", "format for specific result. <result name>=<format string>", v => formatList.Add(v) }, { "j|job=", "<job name>#<job parameters semicolon separated>#<request results semicolon separated>#<standard job parameters semicolon separated>.\nFor binary job parameters prepend the hex string with| (e.g. |A3C2)", v => jobNames.Add(v) }, { "h|help", "show this message and exit", v => showHelp = v != null }, }; try { p.Parse(args); } catch (OptionException e) { string thisName = Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName); Console.Write(thisName + ": "); Console.WriteLine(e.Message); Console.WriteLine("Try `" + thisName + " --help' for more information."); return(1); } if (showHelp) { ShowHelp(p); return(0); } _outputWriter = string.IsNullOrEmpty(outFile) ? Console.Out : new StreamWriter(outFile, appendFile, Encoding); try { if (string.IsNullOrEmpty(sgbdFile)) { _outputWriter.WriteLine("No sgbd file specified"); return(1); } if (jobNames.Count < 1) { _outputWriter.WriteLine("No jobs specified"); return(1); } _outputWriter.WriteLine("API Version: {0}.{1}.{2}", (EdiabasNet.EdiabasVersion >> 8) & 0xF, (EdiabasNet.EdiabasVersion >> 4) & 0xF, EdiabasNet.EdiabasVersion & 0xF); if (storeResults) { _apiResultList = new List <List <Dictionary <string, EdiabasNet.ResultData> > >(); } using (EdiabasNet ediabas = new EdiabasNet(cfgString)) { if (string.IsNullOrEmpty(ifhName)) { ifhName = ediabas.GetConfigProperty("Interface"); } EdInterfaceBase edInterface; if (!string.IsNullOrEmpty(ifhName)) { if (EdInterfaceObd.IsValidInterfaceNameStatic(ifhName)) { edInterface = new EdInterfaceObd(); } else if (EdInterfaceEdic.IsValidInterfaceNameStatic(ifhName)) { edInterface = new EdInterfaceEdic(); } else if (EdInterfaceAds.IsValidInterfaceNameStatic(ifhName)) { edInterface = new EdInterfaceAds(); } else if (EdInterfaceEnet.IsValidInterfaceNameStatic(ifhName)) { edInterface = new EdInterfaceEnet(); } else { _outputWriter.WriteLine("Interface not valid"); return(1); } } else { edInterface = new EdInterfaceObd(); } ediabas.EdInterfaceClass = edInterface; ediabas.ProgressJobFunc = ProgressJobFunc; ediabas.ErrorRaisedFunc = ErrorRaisedFunc; if (!string.IsNullOrEmpty(comPort)) { // ReSharper disable ConditionIsAlwaysTrueOrFalse // ReSharper disable IsExpressionAlwaysTrue // ReSharper disable HeuristicUnreachableCode if (edInterface is EdInterfaceObd) { ((EdInterfaceObd)edInterface).ComPort = comPort; } else if (edInterface is EdInterfaceEdic) { ((EdInterfaceEdic)edInterface).ComPort = comPort; } else if (edInterface is EdInterfaceAds) { ((EdInterfaceAds)edInterface).ComPort = comPort; } else if (edInterface is EdInterfaceEnet) { ((EdInterfaceEnet)edInterface).RemoteHost = comPort; } // ReSharper restore ConditionIsAlwaysTrueOrFalse // ReSharper restore once IsExpressionAlwaysTrue // ReSharper restore once HeuristicUnreachableCode } ediabas.SetConfigProperty("EcuPath", Path.GetDirectoryName(sgbdFile)); foreach (string jobString in jobNames) { if (jobString.Length == 0) { _outputWriter.WriteLine("Empty job string"); return(1); } ediabas.ArgBinary = null; ediabas.ArgBinaryStd = null; ediabas.ResultsRequests = string.Empty; string[] parts = jobString.Split('#'); if ((parts.Length < 1) || (parts[0].Length == 0)) { _outputWriter.WriteLine("Empty job name"); return(1); } string jobName = parts[0]; if (parts.Length >= 2) { string argString = parts[1]; if (argString.Length > 0 && argString[0] == '|') { // binary data ediabas.ArgBinary = EdiabasNet.HexToByteArray(argString.Substring(1)); } else { ediabas.ArgString = argString; } } if (parts.Length >= 3) { ediabas.ResultsRequests = parts[2]; } if (parts.Length >= 4) { string argString = parts[3]; if (argString.Length > 0 && argString[0] == '|') { // binary data ediabas.ArgBinaryStd = EdiabasNet.HexToByteArray(argString.Substring(1)); } else { ediabas.ArgStringStd = argString; } } string sgbdFileUse = sgbdFile; if (parts.Length >= 5) { sgbdFileUse = parts[4]; } _outputWriter.WriteLine("JOB: " + jobName); try { ediabas.ResolveSgbdFile(Path.GetFileNameWithoutExtension(sgbdFileUse)); } catch (Exception ex) { if (!_compareOutput) { _outputWriter.WriteLine("ResolveSgbdFile failed: " + EdiabasNet.GetExceptionText(ex)); } return(1); } try { ediabas.ExecuteJob(jobName); } catch (Exception ex) { if (!_compareOutput || ediabas.ErrorCodeLast == EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE) { _outputWriter.WriteLine("Job execution failed: " + EdiabasNet.GetExceptionText(ex)); } return(1); } List <Dictionary <string, EdiabasNet.ResultData> > resultSets = ediabas.ResultSets; if (_apiResultList != null) { _apiResultList.Add(resultSets); } else { PrintResults(formatList, printAllTypes, resultSets); } //Console.WriteLine("Press Key to continue"); //Console.ReadKey(true); } if (_apiResultList != null) { foreach (List <Dictionary <string, EdiabasNet.ResultData> > resultSets in _apiResultList) { PrintResults(formatList, printAllTypes, resultSets); } } } } catch (Exception ex) { _outputWriter.WriteLine(ex.Message); return(1); } finally { _outputWriter.Close(); } return(0); }