mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-12 16:58:30 +00:00
Improved SerialConnection async-implementations
This commit is contained in:
parent
1f6c3eaedf
commit
0d7dc3756b
@ -59,30 +59,16 @@ public class SerialConnection : ISerialConnection
|
|||||||
|
|
||||||
public void Dispose() => _serialPort.Dispose();
|
public void Dispose() => _serialPort.Dispose();
|
||||||
|
|
||||||
public Task ConnectAsync()
|
public async Task ConnectAsync()
|
||||||
{
|
{
|
||||||
try
|
await Task.Yield();
|
||||||
{
|
Connect();
|
||||||
Connect();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Task.FromException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task WriteAsync(byte[] data)
|
public async Task WriteAsync(byte[] data)
|
||||||
{
|
{
|
||||||
try
|
await Task.Yield();
|
||||||
{
|
Write(data);
|
||||||
Write(data);
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Task.FromException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(byte[] data) => _serialPort.Write(data, 0, data.Length);
|
public void Write(byte[] data) => _serialPort.Write(data, 0, data.Length);
|
||||||
@ -151,30 +137,16 @@ public class SerialConnection : ISerialConnection
|
|||||||
|
|
||||||
public void Dispose() => _serialPort.Dispose();
|
public void Dispose() => _serialPort.Dispose();
|
||||||
|
|
||||||
public Task ConnectAsync()
|
public async Task ConnectAsync()
|
||||||
{
|
{
|
||||||
try
|
await Task.Yield();
|
||||||
{
|
Connect();
|
||||||
Connect();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Task.FromException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task WriteAsync(byte[] data)
|
public async Task WriteAsync(byte[] data)
|
||||||
{
|
{
|
||||||
try
|
await Task.Yield();
|
||||||
{
|
Write(data);
|
||||||
Write(data);
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Task.FromException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(byte[] data) => _serialPort.Write(data, 0, data.Length);
|
public void Write(byte[] data) => _serialPort.Write(data, 0, data.Length);
|
||||||
|
|||||||
@ -16,7 +16,6 @@ public class SerialException : Exception
|
|||||||
public SerialException(string message, Exception innerException)
|
public SerialException(string message, Exception innerException)
|
||||||
: base(message, innerException)
|
: base(message, innerException)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user