1
0
mirror of https://github.com/DarthAffe/OBD.NET.git synced 2025-12-12 16:58:30 +00:00

Added ConsoleClient example

This commit is contained in:
Roman Lumetsberger 2017-05-08 21:57:32 +02:00
parent 2b5b56a870
commit ede7de0411
6 changed files with 196 additions and 0 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ODB.NET.ConsoleClient</RootNamespace>
<AssemblyName>ODB.NET.ConsoleClient</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OBD.NET.Common\OBD.NET.Common.csproj">
<Project>{D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}</Project>
<Name>OBD.NET.Common</Name>
</ProjectReference>
<ProjectReference Include="..\ODB.NET.Desktop\ODB.NET.Desktop.csproj">
<Project>{14CB98E1-95DE-4923-8896-FDF5171AA49E}</Project>
<Name>ODB.NET.Desktop</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,56 @@
using OBD.NET.Common.Logging;
using OBD.NET.Communication;
using OBD.NET.Devices;
using OBD.NET.Logging;
using OBD.NET.OBDData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ODB.NET.ConsoleClient
{
/// <summary>
/// Console test client
/// </summary>
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Parameter ComPort needed.");
return;
}
var 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.Initialize();
dev.RequestData<FuelType>();
for (int i = 0; i < 5; i++)
{
dev.RequestData<EngineRPM>();
dev.RequestData<VehicleSpeed>();
Thread.Sleep(1000);
}
Console.ReadLine();
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ODB.NET.ConsoleClient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ODB.NET.ConsoleClient")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8f8ec5d5-94bd-47cf-9714-ca8c0198bddc")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,35 @@
using OBD.NET.Logging;
using System;
using System.Diagnostics;
namespace OBD.NET.Common.Logging
{
/// <summary>
/// Simple console logger
/// </summary>
/// <seealso cref="OBD.NET.Logging.IOBDLogger" />
public class OBDConsoleLogger : IOBDLogger
{
public OBDLogLevel LogLevel { get; set; }
public OBDConsoleLogger()
{
LogLevel = OBDLogLevel.None;
}
public OBDConsoleLogger(OBDLogLevel level)
{
LogLevel = level;
}
public void WriteLine(string text, OBDLogLevel level)
{
if (LogLevel == OBDLogLevel.None) return;
if((int)level >= (int)LogLevel)
{
Console.WriteLine($"{DateTime.Now.ToString()} - {level} - {text}");
}
}
}
}

View File

@ -42,6 +42,7 @@
<ItemGroup>
<Compile Include="Communication\EnhancedSerialPort.cs" />
<Compile Include="Communication\SerialConnection.cs" />
<Compile Include="Logging\ODBConsoleLogger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>