I've written a Python QGIS plugin that reads data from an AIS receiver via the Serial package. It will be similar in function to the GPS Information panel in that it will show your position on the map canvas and work in the background allowing the user to continue using QGIS.
I've written a while loop such that on a button click; QGIS will constantly monitor the serial port for a message. Once a message is received in its entirety (using readline()) the loop begins again.
I have now run into an issue I didn't plan for in that while the loop is running I can't do anything else with QGIS until I terminate this loop. Obviously my intention is that this plugin will work in the background (like GPS information panel) and that the user can do their normal GIS tasks.
Can anyone point me in the right direction. I'm not sure if there is a specific terminology for what I'm trying to achieve.
def connectAIS(self):
with serial.Serial(port=self.dockwidget.cb_comPort.currentText(), baudrate=self.dockwidget.cb_baudRate.currentText(),
parity='N', stopbits=1, bytesize=8, timeout=None) as ser:
while ser.isOpen():
self.dockwidget.l_status.setText("scanning")
dataOut = open('//positionLogger.txt', 'a')
aismsg = ser.readline()
dataOut.write(str('\n' + str(aismsg)))
dataOut.close()
self.dockwidget.l_rawData.setText(str(aismsg))