def connectionCall(self): """Function to connect to pump, motor and arduino""" try: Arduino.connect() except: print("arduino connection problem") if Arduino.isconnected(): self.label_ard.setPixmap(self.pixmap_1) else: self.label_ard.setPixmap(self.pixmap_0) try: Pump_seringe.connect() except: print("pump connection problem") if Pump_seringe.isconnected(): self.label_pum.setPixmap(self.pixmap_1) else: self.label_pum.setPixmap(self.pixmap_0) try: MotorPI.connect() except: print("motor connection problem") if MotorPI.isconnected(): self.label_mot.setPixmap(self.pixmap_1) else: self.label_mot.setPixmap(self.pixmap_0)
def TestConnectionCall(self): ####################################################### ## CONNECTION WITH ARDUINO/PUMP/MOTOR msg = "" try: Arduino.connect() except: print("Can't connect to arduino") if Arduino.isconnected(): msg += "Arduino: Connected\n" else: msg += "Arduino: Not connected\n" try: Pump_seringe.connect() except: print("Can't connect to pump") if Pump_seringe.isconnected(): msg += "Pump: Connected\n" else: msg += "Pump: Not connected\n" try: MotorPI.connect() #MotorPI.ref() except: print("Can't connect to motor") if MotorPI.isconnected(): msg += "Motor: Connected\n" else: msg += "Motor: Not connected\n" QMessageBox.about(self, "Connections", msg)
def passCall(self): """Function to pass directly to the test window""" self.connectionCall() #Verify the connection #Show a message with the current connection states msg = "" if Arduino.isconnected(): msg += "Arduino: Connected\n" else: msg += "Arduino: Not connected\n" if Pump_seringe.isconnected(): msg += "Pump: Connected\n" else: msg += "Pump: Not connected\n" if MotorPI.isconnected(): msg += "Motor: Connected\n" else: msg += "Motor: Not connected\n" msg = QMessageBox.question(self, "Continue ?", msg + "\n\nDo you want to continue ?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if msg == QMessageBox.No: return QMessageBox.about( self, "Acquisition", "Initialisation finished\n\nStart of the acquisition") self.switch_window.emit( self.path) #Send the signal to change window to test window self.close() #Close the initialisation window
def ini_processCall(self): """Function that initialise: start the motor to find upper and lower boundaries""" #Button check not more than one time if self.ini_start: return self.ini_start = True #Define the progress bar self.completed = 0 ####################################################### # Define the connections with devices self.label.setText("Connecting...") self.repaint() time.sleep(1) ####################################################### ## CONNECTION WITH ARDUINO/PUMP/MOTOR self.connectionCall() msg = "" if Arduino.isconnected(): msg += "Arduino: Connected\n" else: msg += "Arduino: Not connected\n" if Pump_seringe.isconnected(): msg += "Pump: Connected\n" else: msg += "Pump: Not connected\n" if MotorPI.isconnected(): msg += "Motor: Connected\n" else: msg += "Motor: Not connected\n" QMessageBox.about(self, "Connections", msg) if Arduino.isconnected() == False or MotorPI.isconnected( ) == False or Pump_seringe.isconnected() == False: print('Connection problem') self.ini_start = False self.label.setText("Waiting") return secu = 0 test = 0 while test == 0: try: [secu, ori, F, P] = read_arduino() test = 1 except: print("read step1 problem") if secu == 1: QMessageBox.about(self, "Problem", "Security button activated !") self.completed = 0 self.ini_start = False self.timer_ini.stop() return msg = QMessageBox.question( self, "Continue ?", "Do you want to start the initialisation ?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if msg == QMessageBox.No: self.ini_start = False return ####################################################### ## SEARCH FOR BOUNDARIES self.completed = 0 self.progress.setValue(self.completed) self.label.setText("Searching for origin") self.repaint() #First boundary try: MotorPI.vel(55) except: QMessageBox.about(self, "Problem", "Retry please") self.ini_start = False self.timer_ini.stop() MotorPI.disconnect() return MotorPI.ref() try: MotorPI.move_rel(50) except: QMessageBox.about(self, "Problem", "Retry please") self.ini_start = False self.timer_ini.stop() return while ori == 0: if self.completed >= 100: self.completed = 0 self.progress.setValue(self.completed) time.sleep(0.1) try: [secu, ori, F, P] = read_arduino() except: print("read step1 problem") self.completed = self.completed + 20 self.progress.setValue(self.completed) time.sleep(0.5) try: [secu, ori, F, P] = read_arduino() except: print("read step1 problem") if secu == 1: QMessageBox.about(self, "Problem", "Security button activated !") self.completed = 0 self.ini_start = False self.timer_ini.stop() return try: MotorPI.stop() except: print("motor stop") MotorPI.ref() self.completed = 100 self.progress.setValue(self.completed) # QMessageBox.about(self, "Origin", "The origin was found successfully") time.sleep(1) self.completed = 0 self.progress.setValue(self.completed) self.label.setText("Returning mid") self.repaint() #Return L_return = -50 MotorPI.move_rel(L_return) deg = 360 * abs(L_return) / MotorPI.p t = deg / MotorPI.vel_value() debut = time.time() limit = t / 99 while MotorPI.ismoving(): if time.time() - debut > limit: self.completed = self.completed + 1 self.progress.setValue(self.completed) limit = limit + t / 99 try: [secu, ori, F, P] = read_arduino() except: print("read step1 problem") if secu == 1: QMessageBox.about(self, "Problem", "Security button activated !") self.ini_start = False self.timer_ini.stop() return self.completed = 100 self.progress.setValue(self.completed) self.label.setText("Finish") MotorPI.vel(20) self.timer_ini.stop() QMessageBox.about( self, "Acquisition", "Initialisation finished\n\nStart of the acquisition") self.switch_window.emit(self.path) self.close()