async private void SimulateConnection() { isConnectedToObd = await OBDDevice.Initialize(true); if (isConnectedToObd) { await StartStreaming(); } }
async private void Connect() { isConnectedToObd = await OBDDevice.Initialize(); if (isConnectedToObd) { await StartStreaming(); } }
async void AddOBDDataToPoint(TripPoint point) { //Read data from the OBD device point.HasOBDData = false; Dictionary <string, string> obdData = null; //if (obdDataProcessor != null) obdData = OBDDevice.ReadData(); if (obdData != null) { double speed = -255, rpm = -255, efr = -255, el = -255, stfb = -255, ltfb = -255, fr = -255, tp = -255, rt = -255, dis = -255, rtp = -255; var vin = String.Empty; if (obdData.ContainsKey("el") && !string.IsNullOrWhiteSpace(obdData["el"])) { if (!double.TryParse(obdData["el"], out el)) { el = -255; } } if (obdData.ContainsKey("stfb")) { double.TryParse(obdData["stfb"], out stfb); } if (obdData.ContainsKey("ltfb")) { double.TryParse(obdData["ltfb"], out ltfb); } if (obdData.ContainsKey("fr")) { double.TryParse(obdData["fr"], out fr); if (fr != -255) { fuelConsumptionRate = fr; } } if (obdData.ContainsKey("tp")) { double.TryParse(obdData["tp"], out tp); } if (obdData.ContainsKey("rt")) { double.TryParse(obdData["rt"], out rt); } if (obdData.ContainsKey("dis")) { double.TryParse(obdData["dis"], out dis); } if (obdData.ContainsKey("rtp")) { double.TryParse(obdData["rtp"], out rtp); } if (obdData.ContainsKey("spd")) { double.TryParse(obdData["spd"], out speed); } if (obdData.ContainsKey("rpm")) { double.TryParse(obdData["rpm"], out rpm); } if (obdData.ContainsKey("efr") && !string.IsNullOrWhiteSpace(obdData["efr"])) { if (!double.TryParse(obdData["efr"], out efr)) { efr = -255; } } else { efr = -255; } if (obdData.ContainsKey("vin")) { vin = obdData["vin"]; } point.EngineLoad = el; point.ShortTermFuelBank = stfb; point.LongTermFuelBank = ltfb; point.MassFlowRate = fr; point.ThrottlePosition = tp; point.Runtime = rt; point.DistanceWithMalfunctionLight = dis; point.RelativeThrottlePosition = rtp; point.Speed = speed; point.RPM = rpm; point.EngineFuelRate = efr; point.VIN = vin; #if DEBUG foreach (var kvp in obdData) { Console.WriteLine($"{kvp.Key} {kvp.Value}"); } #endif point.HasOBDData = true; } }
private void setDevice(int device) { m_iDevice = device; switch (device) { case 1: m_commLog.AddItem("Set device to ELM327"); m_obdDevice = (OBDDevice)new OBDDeviceELM327(m_commLog); break; case 2: m_commLog.AddItem("Set device to ELM320"); m_obdDevice = (OBDDevice)new OBDDeviceELM320(m_commLog); break; case 3: m_commLog.AddItem("Set device to ELM322"); m_obdDevice = (OBDDevice)new OBDDeviceELM322(m_commLog); break; case 4: m_commLog.AddItem("Set device to ELM323"); m_obdDevice = (OBDDevice)new OBDDeviceELM323(m_commLog); break; default: m_commLog.AddItem("Set device to ELM327"); m_obdDevice = (OBDDevice)new OBDDeviceELM327(m_commLog); break; } }