mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2026-11-09 12:06:25 +00:00
Improved SerialConnection async-implementations
This commit is contained in:
1 parent
1f6c3eaedf
commit
0d7dc3756b
2 files changed
+13
-42
No files matched your search
@@ -59,30 +59,16 @@ public class SerialConnection : ISerialConnection
|
||||
|
||||
public void Dispose() => _serialPort.Dispose();
|
||||
|
||||
public Task ConnectAsync()
|
||||
public async Task ConnectAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connect();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
await Task.Yield();
|
||||
Connect();
|
||||
}
|
||||
|
||||
public Task WriteAsync(byte[] data)
|
||||
public async Task WriteAsync(byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
Write(data);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
await Task.Yield();
|
||||
Write(data);
|
||||
}
|
||||
|
||||
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()
|
||||
public async Task ConnectAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connect();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
await Task.Yield();
|
||||
Connect();
|
||||
}
|
||||
|
||||
public Task WriteAsync(byte[] data)
|
||||
public async Task WriteAsync(byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
Write(data);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
await Task.Yield();
|
||||
Write(data);
|
||||
}
|
||||
|
||||
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)
|
||||
: base(message, innerException)
|
||||
{ }
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user