mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2026-11-11 13:06:25 +00:00
Improved SerialConnection async-implementations
This commit is contained in:
1 parent
1f6c3eaedf
commit
0d7dc3756b
2 files changed
+8
-37
No files matched your search
@@ -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);
|
||||||
|
|||||||
@@ -17,6 +17,5 @@ public class SerialException : Exception
|
|||||||
: base(message, innerException)
|
: base(message, innerException)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user