Bitte helfen Sie mit Python!
Verfasst: Montag 17. Februar 2014, 21:51
Guten Abend,
Ich brauche bitte Hilfe mit Python!
Entschuldigung aber mein Deutsch ist leider nicht gut genug, also ich muss in Englisch schreiben...
A hardware device programmed by me follows the enquiries of the computer program, made in Python. It is connected to the computer creating a virtual COM point via USB. The communications, configurations and buttons function correctly, I only have the problem when I want to graphic the data which the hardware device sends, when I put it in the “Automatic” mode, and the device sends the data periodically every second and the PC program gets stuck.
Nevertheless, when I put the the “Manual” mode, it does function correctly, it graphics the data (random data). The manual mode only makes a lecture when you click on the button “Start Ultrasonic Measurement”. I attach 2 screenshots, in the manual mode (OK) and the automatic (PC stuck).
Everything is in the ZIP GUI5.zip which is attached. The program and a txt.file which is called “valores de test” with some random data in order to be able to do a test.
It seems there is some internal "fight" between the 2 flows of data. I can´t attach the files, so if someone who wants to help me can please send me an e-mail to: isdan24@hotmail.com.
Here under I have copied the part of the Python code where the error probably is:
Vielen Dank!
MFG, Bernhard.
Ich brauche bitte Hilfe mit Python!
Entschuldigung aber mein Deutsch ist leider nicht gut genug, also ich muss in Englisch schreiben...
A hardware device programmed by me follows the enquiries of the computer program, made in Python. It is connected to the computer creating a virtual COM point via USB. The communications, configurations and buttons function correctly, I only have the problem when I want to graphic the data which the hardware device sends, when I put it in the “Automatic” mode, and the device sends the data periodically every second and the PC program gets stuck.
Nevertheless, when I put the the “Manual” mode, it does function correctly, it graphics the data (random data). The manual mode only makes a lecture when you click on the button “Start Ultrasonic Measurement”. I attach 2 screenshots, in the manual mode (OK) and the automatic (PC stuck).
Everything is in the ZIP GUI5.zip which is attached. The program and a txt.file which is called “valores de test” with some random data in order to be able to do a test.
It seems there is some internal "fight" between the 2 flows of data. I can´t attach the files, so if someone who wants to help me can please send me an e-mail to: isdan24@hotmail.com.
Here under I have copied the part of the Python code where the error probably is:
Code: Alles auswählen
## start the aquisition
#
def startAcquisition(self):
if self.com_serie.isOpen() == True:
message = str()
message_data = str()
##
## we send here the configuration to the system
if self.automatic_mode.isChecked() == True:
timeToWait = self.box_burst_time.value()
self.btn_stop_acquisition.setEnabled(True) #Activamos el botÛn de stop de adquisiciÛn en modo auto
print "pulse_burst_period"
listCharacter = ["a"] #to avoid that the list is empty
message = "#pulse_burst_period" + str(int(timeToWait)) + "%"
self.com_serie.write(message)
while(listCharacter[len(listCharacter)-1] != '%'):
listCharacter.append(self.com_serie.read())
message = "".join(listCharacter)
message = message[message.find("#"):message.find("%") + 1]
print "recu " + message
print "auto"
listCharacter = ["a"] #to avoid that the list is empty
message = "#mode_auto%"
self.com_serie.write(message)
while(listCharacter[len(listCharacter)-1] != '%'):
listCharacter.append(self.com_serie.read())
message = "".join(listCharacter)
message = message[message.find("#"):message.find("%") + 1]
print "recu " + message
else:
print "manu"
#timeToWait = 1 #0
listCharacter = ["a"] #to avoid that the list is empty
message = "#mode_manual%"
self.com_serie.write(message)
while(listCharacter[len(listCharacter)-1] != '%'):
listCharacter.append(self.com_serie.read())
message = "".join(listCharacter)
message = message[message.find("#"):message.find("%") + 1]
print "recu " + message
## now we get the data
message = "#start%"
self.com_serie.write(message)
time.sleep(1)
listCharacter = ["a"] #to avoid that the list is empty
while(listCharacter[len(listCharacter)-1] != '%'):
listCharacter.append(self.com_serie.read())
message = "".join(listCharacter)
message = message[message.find("#"):message.find("%") + 1]
print "recu " + message
#############################
## Get the data
#############################
self.get_data()
#############################
## Plot them
#############################
print "Ploting..."
self.update_plot()
def automatic_get_data(self):
print "auto get data!"
self.get_data()
self.update_plot()
def get_data(self):
self.dataStr = []
self.data = []
self.datafilter = []
message_data = self.getMessageCom()
print "Estos son los datos " + message_data #debug
message_data = message_data [:len(message_data)-1]
self.dataStr = message_data.split(";")
for data in self.dataStr:
data = int(data)
data = (data * 3300.0) / 4095.0
print data #debug
self.data.append(data)
self.datafilter.append(self.filtre.newInputFilter(data))
def update_plot(self):
self.fenetre.setCurrentIndex(1) #Cambia de pestaÒa y muestra gr·fica
if self.automatic_mode.isChecked() == False:
print "Manual mode"
self.figRaw.axes.clear()
self.figRaw.axes.plot(self.data)
self.figRaw.axes.set_title("Raw data")
self.figRaw.axes.set_xlabel("Time")
self.figRaw.axes.set_ylabel("Voltage")
self.figRaw.draw()
self.figFilter.axes.clear()
self.figFilter.axes.plot(self.datafilter)
self.figFilter.axes.set_title("Filtered data")
self.figFilter.axes.set_xlabel("Time")
self.figFilter.axes.set_ylabel("Voltage")
self.figFilter.draw()
else:
print "Automatic mode"
self.figRaw.axes.plot(self.data)
self.figRaw.draw()
self.figFilter.axes.plot(self.datafilter)
self.figFilter.draw()
self.automatic_get_data() # imprimir de forma contÌnua
#hl.set_xdata(numpy.append(hl.get_xdata(), new_data))
#hl.set_ydata(numpy.append(hl.get_ydata(), new_data))
#plt.draw()
def stopAcquisition(self):
message = "#stop%"
self.com_serie.write(message)
time.sleep(1)
listCharacter = ["a"] #to avoid that the list is empty
while(listCharacter[len(listCharacter)-1] != '%'):
listCharacter.append(self.com_serie.read())
message = "".join(listCharacter)
message = message[message.find("#"):message.find("%") + 1]
print "recu " + message
Vielen Dank!
MFG, Bernhard.