def __init__(self):
     self.port = zs.BinarySerial("COM11",
                                 timeout=20,
                                 inter_char_timeout=0.05)
     self.device = zs.BinaryDevice(self.port, 1)
     self.device.home()
     self.device.send(37, 64)
     """
    def __init__(self, com_port):
        global zaber
        try:
            import zaber.serial as zaber
        except ImportError:
            msg = """Could not import zaber.serial module. Please ensure it is
                installed. It is installable via pip with 'pip install zaber.serial'"""
            raise ImportError(dedent(msg))

        self.port = zaber.BinarySerial(com_port)
 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'])
Example #4
0
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)
Example #5
0
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_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()
Example #7
0
def read_motor_position(comport):
    if usedummyzaber:
        print('dummy zaber reading position')
        variables_motor = {
            'LickPort_Lateral_pos': 1,
            'LickPort_RostroCaudal_pos': 1,
        }
        return variables_motor
    else:
        for zabertry_i in range(
                0, 1000):  # when the COMport is occupied, it will try again
            try:
                with zaber_serial.BinarySerial(comport) as ser:
                    Forward_Backward_device = zaber_serial.BinaryDevice(ser, 1)
                    Left_Right_device = zaber_serial.BinaryDevice(ser, 2)
                    for zabertry_i in range(
                            0, 1000
                    ):  # when the COMport is occupied, it will try again
                        try:
                            pos_Forward_Backward = Forward_Backward_device.get_position(
                            )
                            break
                        except:
                            print('unexpected zaber reply try again')

                    for zabertry_i in range(
                            0, 1000
                    ):  # when the COMport is occupied, it will try again
                        try:
                            pos_Left_Right = Left_Right_device.get_position()
                            break
                        except:
                            print('unexpected zaber reply try again')
                    variables_motor = {
                        'LickPort_Lateral_pos': pos_Left_Right,
                        'LickPort_RostroCaudal_pos': pos_Forward_Backward,
                    }
                    return variables_motor
                    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)
Example #9
0
 def _find_port(self):
     """Find the USB port to which the devices are connected.
     
     Uses the serial number of the USB-to-serial converter found
     in self.config.  If not found, uses the serial port path found
     in self.config.
     """
     usbsnr = self.config.get('Stage Port', 'usbsn')
     matches = []
     for i in serial.tools.list_ports.grep(usbsnr):
         matches.append(i)
     if len(matches) == 0:  # try serial if no usb found
         portpath = self.config.get('Stage Port', 'serialport')
     else:
         portpath = matches[0][0]
     baudrate = self.config.getint('Stage Port', 'baudrate')
     self.port = zb.BinarySerial(portpath,
                                 baud=baudrate,
                                 inter_char_timeout=None)
     self.port._ser.flushInput()
 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()
import zaber.serial as zs
import time
"""
small program to communitcate with zabor motor. Decent documentation at
http://www.zaber.com/support/docs/api/core-python/0.8.1/binary.html/
Other motor functions can be performed using the send function with 
an instruction command number. These can be located at 
https://www.zaber.com/wiki/Manuals/Binary_Protocol_Manual#Quick_Command_Reference

"""

#open port for communication
port = zs.BinarySerial("COM11", timeout=20, inter_char_timeout=0.05)
#connect to specific device
device = zs.BinaryDevice(port, 1)


def slice_routine(start_pos, end_pos, num_steps):
    device.move_abs(start_pos)
    step_size = (end_pos - start_pos) // num_steps
    for i in range(num_steps):
        device.move_rel(step_size)
        frog = device.send(60, 0)
        print(frog)


#find location of motor on rails - uses send functions with quick command number
reply = device.send(60, 0)
print reply.data
# device.home()
device.move_rel(0)