1
0
mirror of https://github.com/DarthAffe/OBD.NET.git synced 2025-12-12 16:58:30 +00:00
This commit is contained in:
Roman Lumetsberger 2017-05-08 21:36:03 +02:00
parent 2ca0e8a899
commit 2b5b56a870
2 changed files with 15 additions and 14 deletions

View File

@ -89,6 +89,7 @@ namespace OBD.NET.Devices
throw;
}
}
public virtual void SendCommand(ATCommand command)
{
@ -164,12 +165,11 @@ namespace OBD.NET.Devices
if (sendCloseProtocol)
{
SendCommand(ATCommand.CloseProtocol);
//Thread.Sleep(500);
}
}
catch { }
_dataReceivedEventHandlers = null;
_dataReceivedEventHandlers.Clear();
base.Dispose();
}

View File

@ -203,21 +203,22 @@ namespace OBD.NET.Devices
while (!commandCancellationToken.IsCancellationRequested)
{
string command = null;
commandQueue.TryTake(out command, Timeout.Infinite, commandCancellationToken.Token);
Logger?.WriteLine("Writing Command: '" + command.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
if (Connection.IsAsync)
if(commandQueue.TryTake(out command, Timeout.Infinite, commandCancellationToken.Token))
{
await Connection.WriteAsync(Encoding.ASCII.GetBytes(command));
}
else
{
Connection.Write(Encoding.ASCII.GetBytes(command));
Logger?.WriteLine("Writing Command: '" + command.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
}
//wait for command to finish
commandFinishedEvent.WaitOne();
if (Connection.IsAsync)
{
await Connection.WriteAsync(Encoding.ASCII.GetBytes(command));
}
else
{
Connection.Write(Encoding.ASCII.GetBytes(command));
}
//wait for command to finish
commandFinishedEvent.WaitOne();
}
}
}