def get_data(port): q = Queue.Queue() # Progress bar pb = ProgressWindow(title="Data Collection", status="Now collecting data!", pulsing = True, comm_queue = q) pb.show() fh = open("data.csv", "w") startTime = time.time() dataBuf = "" print str(port) try: s = serial.Serial(str(port), 9600, timeout = 0.1) except (OSError, serial.SerialException): print("ERROR") print("Start data collect") #pb.updatePulse(False) samps = 60 while 1: now = time.time() buf = s.read(10000) dataBuf += buf ct_arr = dataBuf.split("\n") ct = len(ct_arr) if not ct_arr[-1].isdigit(): s.write("GOGOGO\r\n") if ct >= samps: break #print buf #if (now - startTime >= 10): # break #pb.updateProg(100 * (now - startTime) / 10) #prog = 100 * ct / samps #pb.updateProg(prog) #print "%i/%i %i%%" % (ct, samps, prog) csv_vals = ",".join(dataBuf.split("\r\n")) fh.write(csv_vals) fh.close() s.close() pb.close()
class ProgressProcess(multiprocessing.Process): def __init__(self, comm_queue, **kwargs): multiprocessing.Process.__init__(self) self.comm_queue = comm_queue self.kwargs = kwargs self.closed_cleanly = None def run(self): self.app = QtGui.QApplication(sys.argv) self.window = ProgressWindow(comm_queue = self.comm_queue, **self.kwargs) self.window.show() return(self.app.exec_())
def run(self): self.app = QtGui.QApplication(sys.argv) self.window = ProgressWindow(comm_queue = self.comm_queue, **self.kwargs) self.window.show() return(self.app.exec_())
def get_data(port): q = Queue.Queue() # Progress bar pb = ProgressWindow(title="Data Collection", status="Now collecting data!", pulsing=True, comm_queue=q) pb.show() fh = open("data.csv", "w") startTime = time.time() dataBuf = "" print str(port) try: s = serial.Serial(str(port), 9600, timeout=0.1) except (OSError, serial.SerialException): print("ERROR") print("Start data collect") #pb.updatePulse(False) samps = 60 while 1: now = time.time() buf = s.read(10000) dataBuf += buf ct_arr = dataBuf.split("\n") ct = len(ct_arr) if not ct_arr[-1].isdigit(): s.write("GOGOGO\r\n") if ct >= samps: break #print buf #if (now - startTime >= 10): # break #pb.updateProg(100 * (now - startTime) / 10) #prog = 100 * ct / samps #pb.updateProg(prog) #print "%i/%i %i%%" % (ct, samps, prog) csv_vals = ",".join(dataBuf.split("\r\n")) fh.write(csv_vals) fh.close() s.close() pb.close()
def get_possible_serial_ports(qtapp=None): q = Queue.Queue() # Progress bar pb = ProgressWindow( title="Serial Port Search", status="Searching for serial ports (this may take some time)...", pulsing=True, comm_queue=q) pb.show() print("Searching for serial ports (this may take some time)...") s_ports = serial_ports() if len(s_ports) <= 0: print( "No open serial ports found! Make sure you have enough permissions to open a serial port, and/or the device is plugged in and recognized." ) QtGui.QMessageBox.critical( pb, "Error", "No open serial ports found! Make sure you have enough permissions to open a serial port, and/or the device is plugged in and recognized.", QtGui.QMessageBox.Ok) pb.close() return [] pb.updatePulse(False) pb.updateStatus("Found serial ports, scanning for mic sensor...") pb.updateProg(50) uno_ports = prune_ports_uno(s_ports) if len(uno_ports) <= 0: print( "No open Arduino serial ports found! Make sure you have enough permissions to open a serial port, and/or the device is plugged in and recognized." ) QtGui.QMessageBox.critical( pb, "Error", "No open Arduino serial ports found! Make sure you have enough permissions to open a serial port, and/or the device is plugged in and recognized.", QtGui.QMessageBox.Ok) pb.close() return [] pb.updateProg(100) pb.close() return uno_ports
def get_possible_serial_ports(qtapp = None): q = Queue.Queue() # Progress bar pb = ProgressWindow(title="Serial Port Search", status="Searching for serial ports (this may take some time)...", pulsing = True, comm_queue = q) pb.show() print("Searching for serial ports (this may take some time)...") s_ports = serial_ports() if len(s_ports) <= 0: print("No open serial ports found! Make sure you have enough permissions to open a serial port, and/or the device is plugged in and recognized.") QtGui.QMessageBox.critical(pb, "Error", "No open serial ports found! Make sure you have enough permissions to open a serial port, and/or the device is plugged in and recognized.", QtGui.QMessageBox.Ok) pb.close() return [] pb.updatePulse(False) pb.updateStatus("Found serial ports, scanning for mic sensor...") pb.updateProg(50) uno_ports = prune_ports_uno(s_ports) if len(uno_ports) <= 0: print("No open Arduino serial ports found! Make sure you have enough permissions to open a serial port, and/or the device is plugged in and recognized.") QtGui.QMessageBox.critical(pb, "Error", "No open Arduino serial ports found! Make sure you have enough permissions to open a serial port, and/or the device is plugged in and recognized.", QtGui.QMessageBox.Ok) pb.close() return [] pb.updateProg(100) pb.close() return uno_ports