mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-13 01:08:30 +00:00
Moved common parts into ODB.NET.Common
re-factored SerialConnection to ISerialConnection interface and removed stuff which is not compatible with NetStandard
This commit is contained in:
parent
7e0e2447c7
commit
9dd42cba6f
40
OBD.NET/OBD.NET.Common/Communication/SerialConnection.cs
Normal file
40
OBD.NET/OBD.NET.Common/Communication/SerialConnection.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace OBD.NET.Communication
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Serial connection interface
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="System.IDisposable" />
|
||||||
|
public interface ISerialConnection : IDisposable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this instance is open.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> if this instance is open; otherwise, <c>false</c>.
|
||||||
|
/// </value>
|
||||||
|
bool IsOpen { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when a full line was received
|
||||||
|
/// </summary>
|
||||||
|
event EventHandler<string> MessageReceived;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Connects the serial port.
|
||||||
|
/// </summary>
|
||||||
|
void Connect();
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the specified text to the serial connection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The text.</param>
|
||||||
|
void Write(string text);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -36,7 +36,7 @@ namespace OBD.NET.Devices
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public ELM327(SerialConnection connection, IOBDLogger logger = null)
|
public ELM327(ISerialConnection connection, IOBDLogger logger = null)
|
||||||
: base(connection, logger: logger)
|
: base(connection, logger: logger)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ namespace OBD.NET.Devices
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public STN1170(SerialConnection connection, IOBDLogger logger = null)
|
public STN1170(ISerialConnection connection, IOBDLogger logger = null)
|
||||||
: base(connection, logger)
|
: base(connection, logger)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -11,14 +11,14 @@ namespace OBD.NET.Devices
|
|||||||
|
|
||||||
protected IOBDLogger Logger { get; }
|
protected IOBDLogger Logger { get; }
|
||||||
|
|
||||||
protected SerialConnection Connection { get; }
|
protected ISerialConnection Connection { get; }
|
||||||
protected char Terminator { get; set; }
|
protected char Terminator { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
protected SerialDevice(SerialConnection connection, char terminator = '\r', IOBDLogger logger = null)
|
protected SerialDevice(ISerialConnection connection, char terminator = '\r', IOBDLogger logger = null)
|
||||||
{
|
{
|
||||||
this.Connection = connection;
|
this.Connection = connection;
|
||||||
this.Terminator = terminator;
|
this.Terminator = terminator;
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace OBD.NET.Exceptions
|
namespace OBD.NET.Exceptions
|
||||||
{
|
{
|
||||||
@ -17,10 +16,7 @@ namespace OBD.NET.Exceptions
|
|||||||
public SerialException(string message, Exception innerException)
|
public SerialException(string message, Exception innerException)
|
||||||
: base(message, innerException)
|
: base(message, innerException)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
protected SerialException(SerializationInfo info, StreamingContext context)
|
|
||||||
: base(info, context)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace OBD.NET.Exceptions
|
namespace OBD.NET.Exceptions
|
||||||
{
|
{
|
||||||
@ -34,13 +33,7 @@ namespace OBD.NET.Exceptions
|
|||||||
this.Result = result;
|
this.Result = result;
|
||||||
this.ExpectedResult = expectedResult;
|
this.ExpectedResult = expectedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UnexpectedResultException(SerializationInfo info, StreamingContext context, string result, string expectedResult)
|
|
||||||
: base(info, context)
|
|
||||||
{
|
|
||||||
this.Result = result;
|
|
||||||
this.ExpectedResult = expectedResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
20
OBD.NET/OBD.NET.Common/OBD.NET.Common.csproj
Normal file
20
OBD.NET/OBD.NET.Common/OBD.NET.Common.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard1.6</TargetFramework>
|
||||||
|
<Authors>Wyrez / Roman Lumetsberger</Authors>
|
||||||
|
<Company>-</Company>
|
||||||
|
<Product>OBD.NET</Product>
|
||||||
|
<Description>C#-Library to read/write data from/to a car through an ELM327-/STN1170-Adapter</Description>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Communication\" />
|
||||||
|
<Folder Include="Properties\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user