def pump_init(self, pump_port): self.pser = serial.Serial(pump_port, 19200, timeout=0.1) print("connected to", self.pser.name) pumps = new_era.find_pumps(self.pser) self.pump = pumps[0] self.infuse = False new_era.set_diameter(self.pser, self.pump, dia_1ml) new_era.set_direct(self.pser, self.pump, 1) new_era.set_rate(self.pser, self.pump, flowrate)
def pump_init(self, pump_port): self.pser = serial.Serial(pump_port, 19200, timeout=.1) print('connected to', self.pser.name) pumps = new_era.find_pumps(self.pser) self.pump = pumps[0] self.infuse = False new_era.set_diameter(self.pser, self.pump, dia_1ml) new_era.set_direct(self.pser, self.pump, 1) new_era.set_rate(self.pser, self.pump, flowrate)
def __init__(self): try: self.ser = serial.Serial(serial_port, 19200, timeout=.1) print('Connected to:', self.ser.name) pumps = new_era.find_pumps(self.ser) print(pumps) self.pump = pumps[0] except OSError: print('Cannot find the port.') #sys.exit(1) self._app = QtWidgets.QApplication(sys.argv) self._window = QtWidgets.QWidget() self._window.closeEvent = self.shutDown self._ui = pump_design.Ui_Form() self._ui.setupUi(self._window) # set the default value self.set_default() self.n_steps = 0 # Following are the definition of button and lineEdit functions self._ui.pushButton_godefault.clicked.connect(self.go_default) self._ui.pushButton_run.clicked.connect(self.run_pump) self._ui.pushButton_stop.clicked.connect(self.stop_pump) self._ui.pushButton_adds.clicked.connect( partial(self.add_step, None, None, None)) self._ui.pushButton_dels.clicked.connect(self.delete_steps) self._ui.pushButton_savepro.clicked.connect(self.save_protocol) self._ui.pushButton_loadpro.clicked.connect(self.load_protocol) self._ui.pushButton_runpro.clicked.connect(self.run_protocol) self._ui.pushButton_clearpro.clicked.connect(self.clear_protocol) self._ui.lineEdit_rate.returnPressed.connect(partial(self.set_rate)) self._ui.lineEdit_volume.returnPressed.connect(partial(self.set_vol)) # ------------------Done with definition of buton and lineEdit functions self.protocol_threads = deque() self.protocol_list = deque() self.isrunning = False self._window.show() self._app.exec_()
def initUI(self): self.ser = serial.Serial(serial_port,19200,timeout=.1) print 'connected to',self.ser.name # set grid layout grid = QtGui.QGridLayout() grid.setSpacing(7) # setup two buttons along top self.runbtn = QtGui.QPushButton('Run/Update',self) grid.addWidget(self.runbtn,1,2) self.runbtn.setCheckable(True) self.runbtn.clicked.connect(self.run_update) self.stopbtn = QtGui.QPushButton('Stop',self) grid.addWidget(self.stopbtn,1,3) self.stopbtn.setCheckable(True) self.stopbtn.clicked.connect(self.stop_all) self.volbtn = QtGui.QPushButton('Deliver volume',self) grid.addWidget(self.volbtn,1,4) self.volbtn.setCheckable(True) self.volbtn.clicked.connect(self.deliver_volume) self.habitbtn = QtGui.QPushButton('Habituation',self) grid.addWidget(self.habitbtn,1,5) self.habitbtn.setCheckable(True) self.habitbtn.clicked.connect(self.habituate) # optional column labels grid.addWidget(QtGui.QLabel('Pump number'),2,0) grid.addWidget(QtGui.QLabel('Syringe'),2,1) grid.addWidget(QtGui.QLabel('Contents'),2,2) grid.addWidget(QtGui.QLabel('Flow rate'),2,3) grid.addWidget(QtGui.QLabel('Volume to deliver'), 2,4) grid.addWidget(QtGui.QLabel('Habituation'), 2,5) grid.addWidget(QtGui.QLabel('Current flow rate'),2,6) # find pumps pumps = new_era.find_pumps(self.ser) # interate over pumps, adding a row for each self.mapper = QtCore.QSignalMapper(self) self.primemapper = QtCore.QSignalMapper(self) self.currflow = dict() self.rates = dict() self.prime_btns = dict() self.volume = dict() for i,pump in enumerate(pumps): row = 3+i # add pump number pumplab = QtGui.QLabel('Pump %i'%pump) pumplab.setAlignment(QtCore.Qt.AlignHCenter) grid.addWidget(pumplab,row,0) # add syringe pulldown combo = QtGui.QComboBox(self) [combo.addItem(s) for s in sorted(syringes)] self.mapper.setMapping(combo,pump) combo.activated.connect(self.mapper.map) grid.addWidget(combo,row,1) # add textbox to put syring contents grid.addWidget(QtGui.QLineEdit(),row,2) # add textbox to enter flow rates self.rates[pump] = QtGui.QLineEdit(self) grid.addWidget(self.rates[pump],row,3) self.volume[pump] = QtGui.QLineEdit(self) grid.addWidget(self.volume[pump],row, 4) # self.volume[pump] # add label to show current flow rates self.currflow[pump] = QtGui.QLabel(self) self.currflow[pump].setAlignment(QtCore.Qt.AlignHCenter) grid.addWidget(self.currflow[pump],row,6) # add prime button btn = QtGui.QPushButton('Prime',self) btn.setCheckable(True)# makes the button toggleable self.primemapper.setMapping(btn,pump) btn.clicked.connect(self.primemapper.map) grid.addWidget(btn,row,7) self.prime_btns[pump] = btn # mapper thing self.mapper.mapped.connect(self.update_syringe) self.primemapper.mapped.connect(self.prime_pumps) # set up the status bar self.curr_state = 'Running' self.statusbar = QtGui.QLabel(self) grid.addWidget(self.statusbar,1,6) self.statusbar.setText('Status: '+self.curr_state) # set up the last command bar self.commandbar = QtGui.QLabel(self) grid.addWidget(self.commandbar,row+1,0,1,4) # make the prime state: a set containing the priming pumps self.prime_state = set() #initialize: set all flow rates to zero self.run_update() self.stop_all() [self.update_syringe(p) for p in pumps] self.commandbar.setText('') # keyboard shortcuts QtGui.QShortcut( QtGui.QKeySequence('Space'),self,self.stop_all) # format the page self.setLayout(grid) self.setWindowTitle('Pump control') #self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) # always on top self.show()
def initUI(self): self.ser = serial.Serial(serial_port, 19200, timeout=.1) print 'connected to', self.ser.name # set grid layout grid = QtGui.QGridLayout() grid.setSpacing(5) # setup two buttons along top self.runbtn = QtGui.QPushButton('Run/Update', self) grid.addWidget(self.runbtn, 1, 2) self.runbtn.setCheckable(True) self.runbtn.clicked.connect(self.run_update) self.stopbtn = QtGui.QPushButton('Stop', self) grid.addWidget(self.stopbtn, 1, 3) self.stopbtn.setCheckable(True) self.stopbtn.clicked.connect(self.stop_all) # setup timer stuff self.timerbtn = QtGui.QPushButton('Run with Timer', self) grid.addWidget(self.timerbtn, 2, 2, 1, 2) self.timerbtn.setCheckable(True) self.timerbtn.clicked.connect(self.run_update_timer) label = QtGui.QLabel('Set timer (in minutes):') label2 = QtGui.QLabel('Time remaining:') label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) label2.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) grid.addWidget(label, 3, 1) grid.addWidget(label2, 3, 3) self.timein = QtGui.QLineEdit(self) grid.addWidget(self.timein, 3, 2) # create and display the timer self.label_time = QtGui.QLabel() self.timer = QtCore.QTimer() text = "--:--:--" font = QtGui.QFont("SansSerif", 16, QtGui.QFont.Bold) self.label_time.setFont(font) self.label_time.setText(text) grid.addWidget(self.label_time, 3, 4) # optional column labels grid.addWidget(QtGui.QLabel('Pump number'), 4, 0) grid.addWidget(QtGui.QLabel('Syringe'), 4, 1) grid.addWidget(QtGui.QLabel('Contents'), 4, 2) grid.addWidget(QtGui.QLabel('Flow rate'), 4, 3) grid.addWidget(QtGui.QLabel('Current flow rate'), 4, 4) # find pumps pumps = new_era.find_pumps(self.ser) # interate over pumps, adding a row for each self.mapper = QtCore.QSignalMapper(self) self.primemapper = QtCore.QSignalMapper(self) self.currflow = dict() self.rates = dict() self.prime_btns = dict() for i, pump in enumerate(pumps): row = 5 + i # add pump number pumplab = QtGui.QLabel('Pump %i' % pump) pumplab.setAlignment(QtCore.Qt.AlignHCenter) grid.addWidget(pumplab, row, 0) # add syringe pulldown combo = QtGui.QComboBox(self) [combo.addItem(s) for s in sorted(syringes)] self.mapper.setMapping(combo, pump) combo.activated.connect(self.mapper.map) grid.addWidget(combo, row, 1) # add textbox to put syring contents grid.addWidget(QtGui.QLineEdit(), row, 2) # add textbox to enter flow rates self.rates[pump] = QtGui.QLineEdit(self) grid.addWidget(self.rates[pump], row, 3) # add label to show current flow rates self.currflow[pump] = QtGui.QLabel(self) self.currflow[pump].setAlignment(QtCore.Qt.AlignHCenter) grid.addWidget(self.currflow[pump], row, 4) # add prime button btn = QtGui.QPushButton('Prime', self) btn.setCheckable(True) # makes the button toggleable self.primemapper.setMapping(btn, pump) btn.clicked.connect(self.primemapper.map) grid.addWidget(btn, row, 5) self.prime_btns[pump] = btn # mapper thing self.mapper.mapped.connect(self.update_syringe) self.primemapper.mapped.connect(self.prime_pumps) # set up the status bar self.curr_state = 'Stopped' self.statusbar = QtGui.QLabel(self) grid.addWidget(self.statusbar, 1, 4) self.statusbar.setText('Status: ' + self.curr_state) # set up the last command bar self.commandbar = QtGui.QLabel(self) grid.addWidget(self.commandbar, row + 1, 0, 1, 4) # make the prime state: a set containing the priming pumps self.prime_state = set() #initialize: set all flow rates to zero self.run_update() self.stop_all() [self.update_syringe(p) for p in pumps] self.commandbar.setText('') # keyboard shortcuts QtGui.QShortcut(QtGui.QKeySequence('Space'), self, self.stop_all) # format the page self.setLayout(grid) self.setWindowTitle('Pump control') #self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) # always on top self.show()
def initUI(self): self.ser = serial.Serial(serial_port, 19200, timeout=.1) print('connected to', self.ser.name) # set grid layout grid = QtWidgets.QGridLayout() grid.setSpacing(7) # setup two buttons along top self.runbtn = QtWidgets.QPushButton('Run/Update', self) grid.addWidget(self.runbtn, 1, 2) self.runbtn.setCheckable(True) self.runbtn.clicked.connect(self.run_update) self.stopbtn = QtWidgets.QPushButton('Stop', self) grid.addWidget(self.stopbtn, 1, 3) self.stopbtn.setCheckable(True) self.stopbtn.clicked.connect(self.stop_all) self.volbtn = QtWidgets.QPushButton('Deliver volume', self) grid.addWidget(self.volbtn, 1, 4) self.volbtn.setCheckable(True) self.volbtn.clicked.connect(self.deliver_volume) self.habitbtn = QtWidgets.QPushButton('Habituation', self) grid.addWidget(self.habitbtn, 1, 5) self.habitbtn.setCheckable(True) self.habitbtn.clicked.connect(self.habituate) # optional column labels grid.addWidget(QtWidgets.QLabel('Pump number'), 2, 0) grid.addWidget(QtWidgets.QLabel('Syringe'), 2, 1) grid.addWidget(QtWidgets.QLabel('Contents'), 2, 2) grid.addWidget(QtWidgets.QLabel('Flow rate'), 2, 3) grid.addWidget(QtWidgets.QLabel('Volume to deliver'), 2, 4) grid.addWidget(QtWidgets.QLabel('Habituation'), 2, 5) grid.addWidget(QtWidgets.QLabel('Current flow rate'), 2, 6) # find pumps pumps = new_era.find_pumps(self.ser) print("Find pumps:", pumps) # interate over pumps, adding a row for each self.mapper = QtCore.QSignalMapper(self) self.primemapper = QtCore.QSignalMapper(self) self.currflow = dict() self.rates = dict() self.prime_btns = dict() self.volume = dict() for i, pump in enumerate(pumps): row = 3 + i # add pump number pumplab = QtWidgets.QLabel('Pump %i' % pump) pumplab.setAlignment(QtCore.Qt.AlignHCenter) grid.addWidget(pumplab, row, 0) # add syringe pulldown combo = QtWidgets.QComboBox(self) [combo.addItem(s) for s in sorted(syringes)] self.mapper.setMapping(combo, pump) combo.activated.connect(self.mapper.map) grid.addWidget(combo, row, 1) # add textbox to put syring contents grid.addWidget(QtWidgets.QLineEdit(), row, 2) # add textbox to enter flow rates self.rates[pump] = QtWidgets.QLineEdit(self) grid.addWidget(self.rates[pump], row, 3) self.volume[pump] = QtWidgets.QLineEdit(self) grid.addWidget(self.volume[pump], row, 4) # self.volume[pump] # add label to show current flow rates self.currflow[pump] = QtWidgets.QLabel(self) self.currflow[pump].setAlignment(QtCore.Qt.AlignHCenter) grid.addWidget(self.currflow[pump], row, 6) # add prime button btn = QtWidgets.QPushButton('Prime', self) btn.setCheckable(True) # makes the button toggleable self.primemapper.setMapping(btn, pump) btn.clicked.connect(self.primemapper.map) grid.addWidget(btn, row, 7) self.prime_btns[pump] = btn # mapper thing self.mapper.mapped.connect(self.update_syringe) self.primemapper.mapped.connect(self.prime_pumps) # set up the status bar self.curr_state = 'Running' self.statusbar = QtWidgets.QLabel(self) grid.addWidget(self.statusbar, 1, 6) self.statusbar.setText('Status: ' + self.curr_state) # set up the last command bar self.commandbar = QtWidgets.QLabel(self) grid.addWidget(self.commandbar, row + 1, 0, 1, 4) # make the prime state: a set containing the priming pumps self.prime_state = set() #initialize: set all flow rates to zero self.run_update() self.stop_all() [self.update_syringe(p) for p in pumps] self.commandbar.setText('') # keyboard shortcuts QtWidgets.QShortcut(QtGui.QKeySequence('Space'), self, self.stop_all) # format the page self.setLayout(grid) self.setWindowTitle('Pump control') #self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) # always on top self.show()