mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2026-11-11 13:06:25 +00:00
Implemented fake async-methods on SerialConnection
This commit is contained in:
1 parent
2136aaf0ca
commit
1f6c3eaedf
1 file changed
+50
-6
@@ -23,7 +23,7 @@ public class SerialConnection : ISerialConnection
|
|||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
|
||||||
public event EventHandler<DataReceivedEventArgs>? DataReceived = delegate { };
|
public event EventHandler<DataReceivedEventArgs>? DataReceived = delegate { };
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -59,9 +59,31 @@ public class SerialConnection : ISerialConnection
|
|||||||
|
|
||||||
public void Dispose() => _serialPort.Dispose();
|
public void Dispose() => _serialPort.Dispose();
|
||||||
|
|
||||||
public Task ConnectAsync() => throw new NotSupportedException("Asynchronous operations not supported");
|
public Task ConnectAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Connect();
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Task.FromException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Task WriteAsync(byte[] data) => throw new NotSupportedException("Asynchronous operations not supported");
|
public Task WriteAsync(byte[] data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
@@ -128,10 +150,32 @@ public class SerialConnection : ISerialConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() => _serialPort.Dispose();
|
public void Dispose() => _serialPort.Dispose();
|
||||||
|
|
||||||
|
public Task ConnectAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Connect();
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Task.FromException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Task ConnectAsync() => throw new NotSupportedException("Asynchronous operations not supported");
|
public Task WriteAsync(byte[] data)
|
||||||
|
{
|
||||||
public Task WriteAsync(byte[] data) => throw new NotSupportedException("Asynchronous operations not supported");
|
try
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user