mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-13 01:08:30 +00:00
Updated README.md
This commit is contained in:
parent
c824f5ffe3
commit
09d23dbaa9
79
README.md
79
README.md
@ -2,53 +2,60 @@
|
|||||||
C#-Library to read/write data from/to a car through an ELM327-/STN1170-Adapter
|
C#-Library to read/write data from/to a car through an ELM327-/STN1170-Adapter
|
||||||
|
|
||||||
## Projects
|
## Projects
|
||||||
* [OBD.NET.Common](https://www.nuget.org/packages/OBD.NET.Common) - NetStandard 1.4 Library for platform independent stuff
|
* [OBD.NET](https://www.nuget.org/packages/OBD.NET) - OBD-II implementation in .NET 6/5 and .NET Standard 1.4
|
||||||
* [OBD.NET.Desktop](https://www.nuget.org/packages/OBD.NET.Desktop) - Implemenation of SerialConnection on full .NET Framework
|
|
||||||
* OBD.NET.Universal - Implementation of BluetoothSerialConnection for connecting to Bluetooth Adapter on UWP
|
* OBD.NET.Universal - Implementation of BluetoothSerialConnection for connecting to Bluetooth Adapter on UWP
|
||||||
* OBD.NET.ConsoleClient - Example client application using SerialConnection on full .NET Framework
|
* ConsoleClient - Example client application using SerialConnection, running with .NET 6
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
* Add OBD.NET.Common and OBD.NET.Desktop packages to project
|
* Add the `OBD.NET` package to project
|
||||||
```csharp
|
```csharp
|
||||||
class Program
|
|
||||||
|
public class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length < 1)
|
if (args.Length < 1)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Parameter ComPort needed.");
|
Console.WriteLine("Parameter ComPort needed.");
|
||||||
|
|
||||||
|
IEnumerable<string> availablePorts = SerialConnection.GetAvailablePorts();
|
||||||
|
|
||||||
|
Console.WriteLine("\nAvailable ports:");
|
||||||
|
|
||||||
|
foreach (string port in availablePorts)
|
||||||
|
{
|
||||||
|
Console.WriteLine(port);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var comPort = args[0];
|
string comPort = args[0];
|
||||||
|
|
||||||
using (SerialConnection connection = new SerialConnection(comPort))
|
using SerialConnection connection = new SerialConnection(comPort);
|
||||||
using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug)))
|
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) =>
|
dev.SubscribeDataReceived<EngineRPM>((sender, data) => Console.WriteLine("EngineRPM: " + data.Data.Rpm));
|
||||||
{
|
dev.SubscribeDataReceived<EngineFuelRate>((sender, data) => Console.WriteLine("VehicleSpeed: " + data.Data));
|
||||||
Console.WriteLine("VehicleSpeed: " + data.Data.Speed);
|
|
||||||
});
|
dev.SubscribeDataReceived<IOBDData>((sender, data) => Console.WriteLine($"PID {data.Data.PID.ToHexString()}: {data.Data}"));
|
||||||
|
|
||||||
dev.Initialize();
|
dev.Initialize();
|
||||||
dev.RequestData<FuelType>();
|
dev.RequestData<FuelType>();
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
dev.RequestData<EngineRPM>();
|
dev.RequestData<EngineRPM>();
|
||||||
dev.RequestData<VehicleSpeed>();
|
dev.RequestData<EngineFuelRate>();
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
|
||||||
|
|
||||||
//Async example
|
//Async example
|
||||||
MainAsync(comPort).Wait();
|
// MainAsync(comPort).Wait();
|
||||||
|
|
||||||
|
//Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -58,22 +65,22 @@ class Program
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task MainAsync(string comPort)
|
public static async Task MainAsync(string comPort)
|
||||||
{
|
{
|
||||||
using (SerialConnection connection = new SerialConnection(comPort))
|
using SerialConnection connection = new SerialConnection(comPort);
|
||||||
using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug)))
|
using ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug));
|
||||||
{
|
|
||||||
dev.Initialize();
|
|
||||||
var data = await dev.RequestDataAsync<EngineRPM>();
|
|
||||||
Console.WriteLine("Data: " + data.Rpm);
|
|
||||||
data = await dev.RequestDataAsync<EngineRPM>();
|
|
||||||
Console.WriteLine("Data: " + data.Rpm);
|
|
||||||
var data2 = await dev.RequestDataAsync<VehicleSpeed>();
|
|
||||||
Console.WriteLine("Data: " + data2.Speed);
|
|
||||||
data = await dev.RequestDataAsync<EngineRPM>();
|
|
||||||
Console.WriteLine("Data: " + data.Rpm);
|
|
||||||
|
|
||||||
}
|
dev.Initialize();
|
||||||
|
|
||||||
|
EngineRPM engineRpm = await dev.RequestDataAsync<EngineRPM>();
|
||||||
|
Console.WriteLine("Data: " + engineRpm.Rpm);
|
||||||
|
|
||||||
|
engineRpm = await dev.RequestDataAsync<EngineRPM>();
|
||||||
|
Console.WriteLine("Data: " + engineRpm.Rpm);
|
||||||
|
|
||||||
|
VehicleSpeed vehicleSpeed = await dev.RequestDataAsync<VehicleSpeed>();
|
||||||
|
Console.WriteLine("Data: " + vehicleSpeed.Speed);
|
||||||
|
|
||||||
|
engineRpm = await dev.RequestDataAsync<EngineRPM>();
|
||||||
|
Console.WriteLine("Data: " + engineRpm.Rpm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user