Skip to content

Commit

Permalink
CommsInjection: fix isOpen state
Browse files Browse the repository at this point in the history
MainV2: clean close can instance
  • Loading branch information
meee1 committed Jul 11, 2024
1 parent d15af80 commit a86dbbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ExtLibs/Comms/CommsInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CommsInjection : ICommsSerial
public CommsInjection()
{
BaseStream = new CommsStream(this, 0);
Open();
}
public void AppendBuffer(byte[] indata)
{
Expand All @@ -39,6 +40,7 @@ public void Close()
{
lock (_bufferRX)
_bufferRX.Clear();
IsOpen = false;
}

public void DiscardInBuffer()
Expand All @@ -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)
{
Expand Down Expand Up @@ -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; }
Expand Down
2 changes: 2 additions & 0 deletions MainV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,8 @@ public void doConnect(MAVLinkInterface comPort, string portname, string baud, bo
}
}
can.Stop();
MainV2.comPort.UnSubscribeToPacketType(canref);
}
}
Expand Down

0 comments on commit a86dbbc

Please sign in to comment.