def set_motor_speed(): if usedummyzaber: print('dummy zaber speed set') else: for zabertry_i in range( 0, 1000): # when the COMport is occupied, it will try again try: with zaber_serial.BinarySerial( variables['comport_motor']) as ser: setspeed_cmd = zaber_serial.BinaryCommand(1, 42, 1000000) ser.write(setspeed_cmd) setacc_cmd = zaber_serial.BinaryCommand(1, 43, 1000) ser.write(setacc_cmd) break except zaber_serial.binaryserial.serial.SerialException: print('can' 't access Zaber ' + str(zabertry_i)) time.sleep(.01)
def zaber_refresh(self): for zabertry_i in range( 0, 1000): # when the COMport is occupied, it will try again try: with zaber_serial.BinarySerial( variables['comport_motor']) as ser: Forward_Backward_device = zaber_serial.BinaryDevice(ser, 1) Left_Right_device = zaber_serial.BinaryDevice(ser, 2) pos_Forward_Backward = Forward_Backward_device.get_position( ) pos_Left_Right = Left_Right_device.get_position() getspeed_cmd = zaber_serial.BinaryCommand(1, 53, 42) ser.write(getspeed_cmd) speed1 = ser.read() getspeed_cmd = zaber_serial.BinaryCommand(2, 53, 42) ser.write(getspeed_cmd) speed2 = ser.read() getacc_cmd = zaber_serial.BinaryCommand(1, 53, 43) ser.write(getacc_cmd) acc1 = ser.read() getacc_cmd = zaber_serial.BinaryCommand(2, 53, 43) ser.write(getacc_cmd) acc2 = ser.read() self.handles['motor_COMport_edit'].setText( variables['comport_motor']) self.handles['motor_RC_edit'].setText( str(pos_Forward_Backward)) self.handles['motor_LAT_edit'].setText(str(pos_Left_Right)) self.handles['motor_RC_speed_edit'].setText(str(speed1.data)) self.handles['motor_LAT_speed_edit'].setText(str(speed2.data)) self.handles['motor_RC_acceleration_edit'].setText( str(acc1.data)) self.handles['motor_LAT_acceleration_edit'].setText( str(acc2.data)) break except zaber_serial.binaryserial.serial.SerialException: print('can' 't access Zaber ' + str(zabertry_i)) time.sleep(.01)
def zaber_update_comport(self): comport = self.handles['motor_COMport_edit'].text() try: with zaber_serial.BinarySerial(comport) as ser: getspeed_cmd = zaber_serial.BinaryCommand(1, 53, 42) ser.write(getspeed_cmd) speed1 = ser.read() variables['comport_motor'] = comport except zaber_serial.binaryserial.serial.SerialException: print('motor not found on COM port') self.handles['motor_COMport_edit'].setText( variables['comport_motor'])
def retract_protract_motor(positiontomove): if usedummyzaber: print('dummy zaber moving') else: for zabertry_i in range( 0, 1000): # when the COMport is occupied, it will try again try: with zaber_serial.BinarySerial( variables['comport_motor']) as ser: moveabs_cmd = zaber_serial.BinaryCommand( 1, 20, positiontomove) ser.write(moveabs_cmd) break except zaber_serial.binaryserial.serial.SerialException: print('can' 't access Zaber ' + str(zabertry_i)) time.sleep(.01)
def zaber_move_RC(self): if self.handles['motor_RC_edit'].text().isnumeric(): for zabertry_i in range( 0, 1000): # when the COMport is occupied, it will try again try: with zaber_serial.BinarySerial( variables['comport_motor']) as ser: moveabs_cmd = zaber_serial.BinaryCommand( 1, 20, int(self.handles['motor_RC_edit'].text())) ser.write(moveabs_cmd) time.sleep(variables['waittime']) break except zaber_serial.binaryserial.serial.SerialException: print('can' 't access Zaber ' + str(zabertry_i)) time.sleep(.01) self.zaber_refresh()
def zaber_set_acceleration(self, ch): if self.handles['motor_RC_acceleration_edit'].text( ).isnumeric and self.handles['motor_LAT_acceleration_edit'].text( ).isnumeric(): if ch == 1: data = int(self.handles['motor_RC_acceleration_edit'].text()) elif ch == 2: data = int(self.handles['motor_LAT_acceleration_edit'].text()) for zabertry_i in range( 0, 1000): # when the COMport is occupied, it will try again try: with zaber_serial.BinarySerial( variables['comport_motor']) as ser: setacc_cmd = zaber_serial.BinaryCommand(ch, 43, data) ser.write(setacc_cmd) time.sleep(variables['waittime']) break except zaber_serial.binaryserial.serial.SerialException: print('can' 't access Zaber ' + str(zabertry_i)) time.sleep(.01) self.zaber_refresh()