Last active
December 14, 2015 10:49
-
-
Save Shadow6363/5074611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/subpanel/dataPlot/dataPlot.py b/subpanel/dataPlot/dataPlot.py | |
index 8d879e7..1805a23 100644 | |
--- a/subpanel/dataPlot/dataPlot.py | |
+++ b/subpanel/dataPlot/dataPlot.py | |
@@ -3,6 +3,9 @@ Created on Nov 21, 2012 | |
@author: Ted Carancho | |
''' | |
+from multiprocessing import Manager | |
+import multiprocessing | |
+import time | |
from PyQt4 import QtGui, QtCore | |
from pyqtgraph import PlotCurveItem | |
@@ -19,6 +22,8 @@ class dataPlot(QtGui.QWidget, subpanel): | |
self.ui = Ui_plotWindow() | |
self.ui.setupUi(self) | |
+ self.manager = Manager() | |
+ | |
def start(self, xmlSubPanel, boardConfiguration): | |
'''This method starts a timer used for any long running loops in a subpanel''' | |
self.xmlSubPanel = xmlSubPanel | |
@@ -33,7 +38,7 @@ class dataPlot(QtGui.QWidget, subpanel): | |
self.ui.graphicsView.clear() | |
self.ui.treeWidget.clear() | |
- self.data, self.curves, colors = [], [], [ | |
+ self.data, self.curves, colors = self.manager.list([]), [], [ | |
QtGui.QColor('blue'), | |
QtGui.QColor('red'), | |
QtGui.QColor('lime'), | |
@@ -68,15 +73,42 @@ class dataPlot(QtGui.QWidget, subpanel): | |
telemetry = self.xml.find(self.xmlSubPanel + '/Telemetry').text | |
if telemetry != '': | |
self.comm.write(telemetry) | |
- self.timer = QtCore.QTimer() | |
- self.timer.timeout.connect(self.readContinuousData) | |
- self.timer.start(50) | |
self.startCommThread() | |
self.plot_timer = QtCore.QTimer() | |
self.plot_timer.timeout.connect(self.update_plot) | |
self.plot_timer.start(100) | |
+ | |
+ | |
+ def startCommThread(self): | |
+ self.communicationThread = multiprocessing.Process(target=self.commThread, args=[]) | |
+ self.communicationThread.start() | |
+ | |
+ def commThread(self): | |
+ data = [[0.0] * 128 for _ in xrange(self.plotCount)] | |
+ while True: | |
+ try: | |
+ if self.comm.dataAvailable(): | |
+ rawData = self.comm.read() | |
+ split_data = rawData.split(',') | |
+ | |
+ for i in xrange(self.plotCount): | |
+ try: | |
+ dataValue = split_data[i + self.plotIndex] | |
+ | |
+ data[i].insert(0, float(dataValue)) | |
+ data[i].pop() | |
+ self.data[i] = data[i] | |
+ except: | |
+ pass | |
+ except: | |
+ pass | |
+ | |
+ time.sleep(0.01) | |
+ | |
+ | |
+ | |
def readContinuousData(self): | |
'''This method continually reads telemetry from the AeroQuad''' | |
if self.comm.isConnected() and not self.commData.empty(): | |
@@ -98,6 +130,7 @@ class dataPlot(QtGui.QWidget, subpanel): | |
for i in xrange(self.plotCount): | |
legendRow = self.legend.child(i) | |
if legendRow.checkState(0) == 2: | |
+ legendRow.setText(2, str(self.data[i][0])) | |
self.curves[i].setData(self.data[i]) | |
if self.curves[i] not in self.ui.graphicsView.items(): | |
self.ui.graphicsView.addItem(self.curves[i]) | |
diff --git a/subpanel/subPanelTemplate.py b/subpanel/subPanelTemplate.py | |
index 41d4899..8f49016 100644 | |
--- a/subpanel/subPanelTemplate.py | |
+++ b/subpanel/subPanelTemplate.py | |
@@ -4,8 +4,8 @@ Created on Nov 19, 2012 | |
@author: Ted Carancho | |
''' | |
import time | |
-import threading | |
-import Queue | |
+import multiprocessing | |
+from multiprocessing import Queue | |
from PyQt4 import QtCore | |
class subpanel(object): | |
@@ -17,13 +17,14 @@ class subpanel(object): | |
def __init__(self): | |
self.connected = False | |
self.commState = False | |
+ self.communicationThread = None | |
self.timer = None | |
self.xml = None | |
self.xmlSubPanel = None | |
self.comm = None | |
self.mainUi = None | |
self.boardConfiguration = {} | |
- self.commData = Queue.Queue() | |
+ self.commData = None | |
def initialize(self, commTransport, xml, mainWindow): | |
'''This initializes your class with required external arguments''' | |
@@ -71,33 +72,33 @@ class subpanel(object): | |
print(i) | |
def startCommThread(self): | |
- self.commState = True | |
- self.communicationThread = threading.Thread(target=self.commThread, args=[]) | |
+ self.commData = Queue() | |
+ self.communicationThread = multiprocessing.Process(target=self.commThread, args=[]) | |
self.communicationThread.start() | |
+ #self.communicationThread.join() | |
def commThread(self): | |
'''This runs an independent thread dedicated to reading the comminucations port | |
The data is written to the class variable self.data | |
To exit this thread, set self.commState = False | |
''' | |
- while(self.commState): | |
+ while(True): | |
try: | |
if self.comm.dataAvailable(): | |
self.commData.put(self.comm.read()) | |
else: | |
- time.sleep(0.100) | |
+ time.sleep(0.001) | |
except: | |
- self.commState = False | |
- # Thread halted, flush out comm port | |
- if (self.comm.isConnected()): | |
- self.comm.write(self.xml.find("./Settings/StopTelemetry").text) | |
- self.comm.flushResponse() | |
+ pass#self.commState = False | |
def stop(self): | |
'''This method enables a flag which closes the continuous serial read thread''' | |
- self.commState = False # Halt comm thread | |
+ if self.communicationThread and self.communicationThread.is_alive(): | |
+ self.communicationThread.terminate() | |
time.sleep(0.250) | |
- if self.comm.isConnected() == True: | |
+ if self.comm.isConnected(): | |
+ self.comm.write(self.xml.find("./Settings/StopTelemetry").text) | |
+ self.comm.flushResponse() | |
if self.timer != None: | |
self.timer.timeout.disconnect(self.readContinuousData) | |
self.timer.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment