예제 #1
0
 def _wait_connected(self):
     if not self._isConnected() and not type(self)._isConnecting:
         self._connect()
     if type(self)._isConnecting and not self._isConnected():
         type(self)._mutex.lock()
         print(f"Waiting because of a call to {type(self)._name}")
         type(self)._mutex.unlock()
         type(self)._thread.wait(60000)
         time.sleep(1)
     if not self._isConnected():
         raise HardwareError(f"{type(self)._name} not connected")
예제 #2
0
 def get_image(self, Ntries=3):
     try:
         im = self.cam.grab()
     except PxLerror:
         logError()
         if Ntries <= 0:
             raise HardwareError(f"Failed to grab")
         print(f"Grab fail, retrying")
         self.restart_streaming()
         return self.get_image(Ntries - 1)
     if self.flip_image:
         im = im[::-1, ::-1]
     return im
    def _open_connection(self):
        stage = GCSDevice(HW_conf.GCS_lin_controller_name)

        try_connect(lambda: stage.ConnectUSB(type(self)._ID), GCSError)

        time.sleep(1)
        if stage.qCST()['1'] != HW_conf.GCS_lin_stage_name:
            print(stage.qCST()['1'])
            raise HardwareError("Incorrect stage connected")
        print('Connected', stage.qIDN())
        stage.SVO(1, True)
        if not stage.qFRF()['1']:
            print("Reference move")
            stage.FRF(1)
        return stage
예제 #4
0
 def restart_streaming(self, Ntries=10):
     try:
         next_state = False
         self.cam.streaming = False
         next_state = True
         self.cam.streaming = True
     except PxLerror:
         logError()
         if Ntries <= 0:
             raise HardwareError(
                 f"Failed to restart streaming ({next_state})")
         print(f"Restart fail, retrying ({next_state})")
         warnings.warn(
             RuntimeWarning(f"Can't restart Camera ({next_state})"))
         self.nuclear_option()
         self.restart_streaming(Ntries - 1)
    def _open_connection(self):
        _SN = HW_conf.kinesis_cube_serial

        # Instructs the DeviceManager to build and maintain the list of
        # devices connected.
        DeviceManagerCLI.BuildDeviceList()

        kCubeDCServoMotor = KCubeDCServo.CreateKCubeDCServo(_SN)

        # Establish a connection with the device.
        try_connect(lambda: kCubeDCServoMotor.Connect(_SN),
                    DeviceNotReadyException)

        # Wait for the device settings to initialize. We ask the device to
        # throw an exception if this takes more than 5000ms (5s) to complete.
        kCubeDCServoMotor.WaitForSettingsInitialized(5000)

        # Initialize the DeviceUnitConverter object required for real world
        # unit parameters.
        kCubeDCServoMotor.GetMotorConfiguration(_SN)

        # This starts polling the device at intervals of 250ms (0.25s).
        kCubeDCServoMotor.StartPolling(20)

        # We are now able to enable the device for commands.
        kCubeDCServoMotor.EnableDevice()

        if not (kCubeDCServoMotor.IsActuatorDefined):
            raise HardwareError("Actuator not defined")

        print("Zstage Connected")

        velocity_parameters = kCubeDCServoMotor.GetVelocityParams()
        velocity_parameters.MaxVelocity = Decimal(1)
        kCubeDCServoMotor.SetVelocityParams(velocity_parameters)

        if not kCubeDCServoMotor.Status.IsHomed:
            kCubeDCServoMotor.Home(0)

        return kCubeDCServoMotor
    def _open_connection(self):
        stage = GCSDevice(HW_conf.GCS_cube_controller_name)
        try_connect(lambda: stage.ConnectUSB(HW_conf.cubeName), GCSError)
        #        time.sleep(2)
        stage.WGO([1, 2, 3, 4], [0, 0, 0, 0])
        print('Connected', stage.qIDN())
        if stage.qCST()['1'] != HW_conf.GCS_cube_stage_name:
            print(stage.qCST()['1'])
            raise HardwareError("Incorrect stage connected")

        stage.SVO([1, 2, 3, 4], [True, True, True, False])
        if np.any(np.logical_not(list(stage.qATZ([1, 2, 3]).values()))):
            stage.ATZ([1, 2, 3], [0, 0, 0])
            while not stage.IsControllerReady() or np.any(
                    list(stage.IsMoving([1, 2, 3]).values())):
                time.sleep(0.1)
            stage.VEL([1, 2, 3], [500, 500, 500])
            stage.MOV([1, 2, 3], [50, 50, 50])
            time.sleep(0.1)
        while not stage.IsControllerReady() or np.any(
                list(stage.IsMoving([1, 2, 3]).values())):
            time.sleep(0.1)
        stage.IsRecordingMacro = False
        return stage
예제 #7
0
 def ret(cls, *args, **kargs):
     if cls.isRecordingMacro:
         raise HardwareError(
             "Can't use that function while recording a macro")
     else:
         return f(cls, *args, **kargs)
 def waitReady(self, timeout=30):
     startt = time.time()
     while not self.is_ready():
         time.sleep(.1)
         if time.time() - startt > timeout:
             raise HardwareError("Linear Stage not responding")