def macro_start(self, name, wait=True):
     with MutexContainer(self._mutex):
         self.XYZ_c.MAC_START(name)
     if wait:
         time.sleep(1)
         while self.is_macro_running():
             time.sleep(1)
 def run_waveform(self, time_step, X, wait=True, measure_time_step=None):
     with MutexContainer(self._mutex):
         # Get stage coordinates
         X[:, :3] = self.XmtoXs(X[:, :3])
         self._lastXs = X[-1, :3].copy()
         wait_time = self.XYZ_c.run_waveform(
             time_step, X, measure_time_step=measure_time_step)
     if wait:
         self.XYZ_c.wait_end_wave(wait_time)
    def focus(self,
              stage,
              *,
              start_offset=None,
              stop_offset=None,
              step=None,
              intensity=None,
              Nloops=None,
              wait=False,
              checkid=None,
              change_coordinates=True,
              speed=None,
              quick=None):
        """
        start_offset:
            How far back from current position
        stop_offset:
            How far forth from surrent position
        step:
            Step size
        Nloops default 1:
            Each loop has a 10X smaller step size.
        wait default False:
            Should the thread wait for completion
        """
        if not self.app_delegate.camera_delegate.isZoomed():
            raise FocusError('Must select ROI to focus!')

        if self.thread.isRunning():
            raise FocusError('Already Focusing')

        with MutexContainer(self._mutex):
            self._last_result = None

            if intensity is not None:
                self._settings["intensity"] = intensity
            if start_offset is not None:
                self._settings["From"] = start_offset
            if stop_offset is not None:
                self._settings["To"] = stop_offset
            if step is not None:
                self._settings["Step"] = step
            if Nloops is not None:
                self._settings["Nloops"] = Nloops
            if speed is not None:
                self._settings["speed"] = speed
            if quick is not None:
                self._settings["quick"] = quick

            self.update_settings.emit(self._settings)
            self.thread.set_args(self._settings, stage, checkid,
                                 change_coordinates)
            self.thread.start()

        if wait:
            self.wait_thread()
Exemplo n.º 4
0
 def _set_hardware(self, hardware):
     with MutexContainer(type(self)._mutex):
         type(self)._isConnecting = False
         if hardware is None or hardware == type(self)._hardware:
             return
         type(self)._hardware = hardware
         print(f'{self._name} set')
         if self._isConnected() and self._connect_callback is not None:
             self._connect_callback()
             self.on_connect_signal.emit()
Exemplo n.º 5
0
 def __init__(self, name, connect_callback=None):
     super().__init__()
     with MutexContainer(Hardware_Singleton.__mutex):
         if "_number_instances" not in dir(type(self)):
             type(self)._hardware = None
             type(self)._isConnecting = False
             type(self)._mutex = QtCore.QMutex(QtCore.QMutex.Recursive)
             type(self)._number_instances = 1
             type(self)._name = name
             type(self)._thread = Hardware_Thread(
                 self._set_hardware, self._open_connection)
         else:
             type(self)._number_instances += 1
 
         self._set_attribute("_connect_callback", connect_callback)
         self._connect()
Exemplo n.º 6
0
 def _disconnect(self):
     with MutexContainer(type(self)._mutex):
         if self._isConnected():
             self._close_connection()
             type(self)._hardware = None
Exemplo n.º 7
0
 def _connect(self):
     with MutexContainer(type(self)._mutex):
         if not self._isConnected() and not type(self)._isConnecting:
             type(self)._isConnecting = True
             print(f'{self._name} connecting')
             type(self)._thread.start()
Exemplo n.º 8
0
 def __setattr__(self, name, value):
     self._wait_connected()
     with MutexContainer(type(self)._mutex):
         setattr(type(self)._hardware, name, value)
Exemplo n.º 9
0
 def __getattr__(self, name):
     self._wait_connected()
     with MutexContainer(type(self)._mutex):
         return getattr(type(self)._hardware, name)
    def goto_position(self,
                      XTo,
                      speed=np.nan,
                      *,
                      wait=False,
                      checkid=None,
                      useLastPos=False,
                      isRaw=False):
        """Moves to the position

        Parameters:
        ----------
            Xm:
                Position to go to [um]
            speed:
                Speed [um/s]
            wait:
                Should the call be blocking?
            checkid:
                If the movment is locked, the checkid
            useLastPos:
                Use for performance. Avoid calling pos()
                (Might be useless)
            isRaw:
                Is Xm raw or corrected?

        Note:
            Any value of Xm set to nan will not be moved
        """

        # Check lock
        if not self._checklock(checkid):
            return
        with MutexContainer(self._mutex):
            # get starting point
            XsFrom = None
            if useLastPos:
                XsFrom = self._lastXs
            else:
                XsFrom = self._XSPOS()

            XsTo, XmTo, Vs, travel_time = self.move_parameters(
                XTo, XsFrom, speed, isRaw)

            # Don't move if final = now
            if np.linalg.norm(XsTo - XsFrom) < 1e-3:
                return

            # Move
            self.move_signal.emit(list(XmTo), speed)
            self._MOVVEL(XsTo, Vs)
        # Wait for movment to end
        if wait:
            tstart = time.time()
            self.wait_end_motion(travel_time, 300)
            twait = time.time() - tstart
            if twait - travel_time > 1:
                with open('waitlog.txt', 'a') as f:
                    f.write(
                        f'expected: {travel_time} actual:{twait} from:{XsFrom} to:{XsTo}\r\n'
                    )