public static async Task Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Parameter ComPort needed."); return; } string comPort = args[0]; Console.CancelKeyPress += ConsoleOnCancelKeyPress; using SerialConnection connection = new SerialConnection(comPort); using ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug)); dev.SubscribeDataReceived <EngineRPM>((sender, data) => Console.WriteLine("EngineRPM: " + data.Data.Rpm)); dev.SubscribeDataReceived <VehicleSpeed>((sender, data) => Console.WriteLine("VehicleSpeed: " + data.Data.Speed)); dev.SubscribeDataReceived <IOBDData>((sender, data) => Console.WriteLine($"PID {((byte)data.Data.PID).ToHexString()}: {data.Data}")); dev.Initialize(); dev.RequestData <FuelType>(); while (_requestData) { dev.RequestData <EngineRPM>(); dev.RequestData <VehicleSpeed>(); await Task.Delay(1000); } }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Parameter ComPort needed."); return; } string comPort = args[0]; using (SerialConnection connection = new SerialConnection(comPort)) using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug))) { dev.SubscribeDataReceived <EngineRPM>((sender, data) => Console.WriteLine("EngineRPM: " + data.Data.Rpm)); dev.SubscribeDataReceived <VehicleSpeed>((sender, data) => Console.WriteLine("VehicleSpeed: " + data.Data.Speed)); dev.SubscribeDataReceived <IOBDData>((sender, data) => Console.WriteLine($"PID {data.Data.PID.ToHexString()}: {data.Data}")); dev.Initialize(); dev.RequestData <FuelType>(); for (int i = 0; i < 5; i++) { dev.RequestData <EngineRPM>(); dev.RequestData <VehicleSpeed>(); Thread.Sleep(1000); } } Console.ReadLine(); //Async example //MainAsync(comPort).Wait(); //Console.ReadLine(); }
private static void ContinuousPush(int speepTime, Func <bool> cancellationCriateria) { ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug)); dev.Initialize(); Task.Factory.StartNew(async() => { dev.SubscribeDataReceived <EGRError>((sender, data) => Console.WriteLine("EngineRPM: " + data.Data)); connection.DataReceived += Connection_DataReceived; float lastRpmPushed = -1; while (cancellationCriateria()) { RealTimePayload realTimePayLoad = await GetRealTimePayload(dev); if (lastRpmPushed != 0 || realTimePayLoad.Rpm != 0) { await Push(connection, realTimePayLoad); lastRpmPushed = realTimePayLoad.Rpm; } await Task.Delay(speepTime); } }); }