The program "Mission Planner" allows python scripts to be ran in order to customize the behavior of the program. The "Mission Planner" runs the script in its own thread. When the thread is running I have the option to press the abort button which calls "Thread.Abort()" within "Mission Planner". When I press this button the script aborts but when I run the script again I cannot open the serial port this time. I believe it is because the thread aborts before closing the serial port. Is there a way to robustly handle a Thread.Abort()? Or would it be better to handle this issue when I open the port?
Here is a link to the Mission Planner GitHub
Here is a link to the Mission Planner Program
Below is my Python script.
Note: This is simplified version of my script that demonstrates my problem. My script is intended to run in the background until it is aborted.
import clr
clr.AddReference('System')
from System import *
serialPort = IO.Ports.SerialPort("COM3")
serialPort.BaudRate = 9600
serialPort.DataBits = 8
serialPort.Open()
while 1:
print serialPort.ReadLine()
serialPort.Close()