mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-12 16:58:30 +00:00
Implemented fake async-methods on SerialConnection
This commit is contained in:
parent
2136aaf0ca
commit
1f6c3eaedf
@ -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);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user