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 Task ConnectAsync()
|
||||
{
|
||||
try
|
||||
public async Task ConnectAsync()
|
||||
{
|
||||
await Task.Yield();
|
||||
Connect();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Task WriteAsync(byte[] data)
|
||||
{
|
||||
try
|
||||
public async Task WriteAsync(byte[] data)
|
||||
{
|
||||
await Task.Yield();
|
||||
Write(data);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
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 Task ConnectAsync()
|
||||
{
|
||||
try
|
||||
public async Task ConnectAsync()
|
||||
{
|
||||
await Task.Yield();
|
||||
Connect();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Task WriteAsync(byte[] data)
|
||||
{
|
||||
try
|
||||
public async Task WriteAsync(byte[] data)
|
||||
{
|
||||
await Task.Yield();
|
||||
Write(data);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(byte[] data) => _serialPort.Write(data, 0, data.Length);
|
||||
|
||||
@ -17,6 +17,5 @@ public class SerialException : Exception
|
||||
: base(message, innerException)
|
||||
{ }
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user