コード例 #1
0
ファイル: Program.cs プロジェクト: yadavmk/JustCodeIt_TeamSCM
        /// <summary>
        /// Async example using new RequestDataAsync
        /// </summary>
        /// <param name="comPort">The COM port.</param>
        /// <returns></returns>
        public static async Task MainAsync(string comPort)
        {
            using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug)))
            {
                dev.Initialize();

                EngineRPM rpmData = await dev.RequestDataAsync <EngineRPM>();

                VehicleSpeed speedData = await dev.RequestDataAsync <VehicleSpeed>();

                EngineCoolantTemperature engineCoolantTemperatureData = await dev.RequestDataAsync <EngineCoolantTemperature>();

                //EngineOilTemperature engineOilTemperatureData = await dev.RequestDataAsync<EngineOilTemperature>();
                //FuelTankLevelInput fuelTankLevelInputData = await dev.RequestDataAsync<FuelTankLevelInput>();

                RealTimePayload realTimePayLoad = new RealTimePayload()
                {
                    CarId = "MH12KE2651",
                    Rpm   = rpmData?.Rpm,
                    Speed = speedData?.Speed,
                    CoolantTemperature   = engineCoolantTemperatureData?.Temperature,
                    EngineOilTemperature = 87,
                    FuelLevel            = 90,
                    PayloadTimestamp     = DateTime.UtcNow.Ticks
                };

                HttpClient httpClient = new HttpClient();
                httpClient.MaxResponseContentBufferSize = 256000;
                var                 serviceUri             = new Uri(@"http://obdmicroservice20180827101800.azurewebsites.net/api/realtimepayloads");
                StringContent       realTimePayLoadContent = new StringContent(JsonConvert.SerializeObject(realTimePayLoad), Encoding.UTF8, "application/json");
                HttpResponseMessage response = await httpClient.PostAsync(serviceUri, realTimePayLoadContent);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: stepkillah/OBD.NET
        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);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: yadavmk/JustCodeIt_TeamSCM
        private static async Task <RealTimePayload> GetRealTimePayload(ELM327 device)
        {
            EngineRPM rpmData = await device.RequestDataAsync <EngineRPM>();

            VehicleSpeed speedData = await device.RequestDataAsync <VehicleSpeed>();

            EngineCoolantTemperature engineCoolantTemperatureData = await device.RequestDataAsync <EngineCoolantTemperature>();

            EngineOilTemperature engineOilTemperatureData = await device.RequestDataAsync <EngineOilTemperature>();

            FuelTankLevelInput fuelTankLevelInputData = await device.RequestDataAsync <FuelTankLevelInput>();

            ThrottlePosition throttlePossition = await device.RequestDataAsync <ThrottlePosition>();

            RealTimePayload realTimePayLoad = new RealTimePayload()
            {
                CarId = "MH12KE2651",
                Rpm   = rpmData.Rpm,
                Speed = speedData.Speed,
                CoolantTemperature   = engineCoolantTemperatureData.Temperature,
                EngineOilTemperature = 43,
                FuelLevel            = throttlePossition.Position,
                PayloadTimestamp     = DateTime.UtcNow.Ticks
            };

            return(realTimePayLoad);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: yadavmk/JustCodeIt_TeamSCM
        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);
                }
            });
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: tralivali1234/OBD.NET
        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();
        }
コード例 #6
0
        private async Task ConnectDisconnect(string currentState)
        {
            if (currentState.Equals("Connect"))
            {
                serialConnection = new BluetoothSerialConnection("SPP");

                dev = new ELM327(serialConnection, new OBDConsoleLogger(OBDLogLevel.Debug));

                while (!serialConnection.IsOpen)
                {
                    try
                    {
                        await dev.InitializeAsync();
                    }
                    catch (Exception)
                    {
                    }
                }

                connectionBtn.Content = "Disconnect";
            }
            else
            {
                serialConnection.Dispose();
                dev.Dispose();
                connectionBtn.Content = "Connect";
            }
        }
コード例 #7
0
 public void Dispose()
 {
     _isRunning = false;
     _dev?.Dispose();
     _dev = null;
     _connection?.Dispose();
     _connection = null;
 }
コード例 #8
0
        public async Task Initialize()
        {
            if (_isRunning)
            {
                return;
            }

            _connection = new BluetoothSerialConnection("SPP");
            _dev        = new ELM327(_connection);
            await _dev.InitializeAsync();

            _isRunning = true;
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: stepkillah/OBD.NET
        /// <summary>
        /// Async example using new RequestDataAsync
        /// </summary>
        /// <param name="comPort">The COM port.</param>
        /// <returns></returns>
        public static async Task MainAsync(string comPort)
        {
            using SerialConnection connection = new SerialConnection(comPort);
            using ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug));
            dev.Initialize();
            EngineRPM data = await dev.RequestDataAsync <EngineRPM>();

            Console.WriteLine("Data: " + data.Rpm);
            data = await dev.RequestDataAsync <EngineRPM>();

            Console.WriteLine("Data: " + data.Rpm);
            VehicleSpeed data2 = await dev.RequestDataAsync <VehicleSpeed>();

            Console.WriteLine("Data: " + data2.Speed);
            data = await dev.RequestDataAsync <EngineRPM>();

            Console.WriteLine("Data: " + data.Rpm);
        }
コード例 #10
0
 // now we're getting to the good stuff
 private void ConnectBluetooth_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (SerialConnection connection = new SerialConnection(comPortList.Text))
             using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug)))
             {
                 // this is just a test to see if the method does anything so far
                 // Note to self: I need to plan out what the GUI looks like before deciding what to do
                 // with the info gathered
                 MessageBox.Show("CONNECTED :D");
             }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }