diff --git a/ExtLibs/Comms/CommsInjection.cs b/ExtLibs/Comms/CommsInjection.cs index 6c7ca63e53..d895f6ed2f 100644 --- a/ExtLibs/Comms/CommsInjection.cs +++ b/ExtLibs/Comms/CommsInjection.cs @@ -18,6 +18,7 @@ public class CommsInjection : ICommsSerial public CommsInjection() { BaseStream = new CommsStream(this, 0); + Open(); } public void AppendBuffer(byte[] indata) { @@ -39,6 +40,7 @@ public void Close() { lock (_bufferRX) _bufferRX.Clear(); + IsOpen = false; } public void DiscardInBuffer() @@ -51,10 +53,14 @@ public void Open() { lock (_bufferRX) _bufferRX.Clear(); + IsOpen = true; } public int Read(byte[] buffer, int offset, int count) { + if (!IsOpen) + throw new IOException("CommsInjection not open"); + var counttimeout = 0; while (BytesToRead == 0) { @@ -174,7 +180,7 @@ public int BytesToRead public int DataBits { get; set; } public bool DtrEnable { get; set; } - public bool IsOpen => true; + public bool IsOpen { get; private set; } = false; public string PortName { get; set; } public int ReadBufferSize { get; set; } diff --git a/MainV2.cs b/MainV2.cs index cbde55ac89..4edefffec9 100644 --- a/MainV2.cs +++ b/MainV2.cs @@ -1801,6 +1801,8 @@ public void doConnect(MAVLinkInterface comPort, string portname, string baud, bo } } + can.Stop(); + MainV2.comPort.UnSubscribeToPacketType(canref); } }