I am building an application where I acquire data continuously from a National Instruments device and do some real time processing on it. I am trying to hook the acquisition part to a PyQt GUI so that the user can start, stop and configure the data acquisition and see the data. I have one class for the data acquisition and one class for the GUI. I start the data acquisition process as a thread within the GUI:
# data acquisition class
class intensimetre():
#initialize the data acquisition
def __init__(self,app=None,l1=None,l2=None,l3=None):
#...
#start the data acquisition
def demarrer(self,fs=51200.,sensibilite0=12.2,sensibilite1=10.7, rho=1.21, espaceur=0.012, c=343):
#start the acquisition task
nidaq.DAQmxStartTask(tache)
#if i add this line it works
#raw_input(u'appuyez sur entree pour continuer')
#gui class
class GUI_acquisition(QtGui.QWidget):
def __init__(self, app=None):
super(GUI_acquisition, self).__init__()
#create the gui
#...
#create an instance of the data acquisition class
self.intensimetre=
intensimetre(app=self.app,l1=self.l1,l2=self.l2,l3=self.l3)
def demarrer(self):
#start the data acquisition in a thread
t = threading.Thread(target=self.intensimetre.demarrer)
t.start()
The problem is that the application crashes as soon as I start the data acquisition. If I add the raw_input line after starting the acquisition, then it works as it should. However, it doesn't feel like the right way to do it. It seems that once the acquisition is started, the thread returns and the callbacks from the acquisition are not processed properly. Any idea of how to fix this?
Update
I've replaced the raw_input
line by an infinite loop polling the state a status attribute:
while self.isRunning:
sleep(0.1)
I set the isRunning
to True
attribute when the user presses the start button and to False
upon pressing of the stop button. While this works, I don't like polling as I think it can have a negative impact on the performance of my app.