Skip to content

Commit 95078b6

Browse files
reopen serial fix
1 parent 31a16dc commit 95078b6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

BK7231Flasher/Flashers/BK7231Flasher.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ public class BK7231Flasher : BaseFlasher
2525
public static string EMPTY_ENCRYPTION_KEY = "00000000 00000000 00000000 00000000";
2626
bool openPort()
2727
{
28+
// Close any previously open port before re-opening
29+
if (serial != null)
30+
{
31+
try
32+
{
33+
if (serial.IsOpen)
34+
serial.Close();
35+
serial.Dispose();
36+
}
37+
catch { }
38+
serial = null;
39+
}
2840
try
2941
{
3042
serial = new SerialPort(serialName, 115200, Parity.None, 8, StopBits.One);
@@ -60,8 +72,10 @@ public override void closePort()
6072
{
6173
serial.Close();
6274
serial.Dispose();
75+
serial = null;
6376
}
6477
}
78+
6579
enum CommandCode
6680
{
6781
LinkCheck = 0,

0 commit comments

Comments
 (0)