diff --git a/OBD.NET/OBD.NET.Common/Devices/ELM327.cs b/OBD.NET/OBD.NET.Common/Devices/ELM327.cs index b08d6ac..6b07d36 100644 --- a/OBD.NET/OBD.NET.Common/Devices/ELM327.cs +++ b/OBD.NET/OBD.NET.Common/Devices/ELM327.cs @@ -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(); } diff --git a/OBD.NET/OBD.NET.Common/Devices/SerialDevice.cs b/OBD.NET/OBD.NET.Common/Devices/SerialDevice.cs index 1d2f2f9..2ca4954 100644 --- a/OBD.NET/OBD.NET.Common/Devices/SerialDevice.cs +++ b/OBD.NET/OBD.NET.Common/Devices/SerialDevice.cs @@ -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(); + } } }