def move(self, device_number, position):
     device = zaber.BinaryDevice(self.port, device_number)
     device.move_abs(position)
     deadline = monotonic() + TIMEOUT
     while device.get_position() != position:
         if monotonic() > deadline:
             msg = "Device did not move to requested position within timeout"
             raise TimeoutError(msg)
 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)
     """
Exemplo n.º 3
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)
 def get_position(self, device_number):
     device = zaber.BinaryDevice(self.port, device_number)
     return device.get_position()
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)