示例#1
0
    def ini_stage(self, controller=None):
        """
            Initialize the controller and stages (axes) with given parameters.

            ============== ================================================ ==========================================================================================
            **Parameters**  **Type**                                         **Description**

            *controller*    instance of the specific controller object       If defined this hardware will use it and will not initialize its own controller instance
            ============== ================================================ ==========================================================================================

            Returns
            -------
            Easydict
                dictionnary containing keys:
                 * *info* : string displaying various info
                 * *controller*: instance of the controller object in order to control other axes without the need to init the same controller twice
                 * *stage*: instance of the stage (axis or whatever) object
                 * *initialized*: boolean indicating if initialization has been done corretly

            See Also
            --------
             daq_utils.ThreadCommand
        """
        try:
            # initialize the stage and its controller status
            # controller is an object that may be passed to other instances of DAQ_Move_Mock in case
            # of one controller controlling multiaxes

            self.status.update(
                edict(info="", controller=None, initialized=False))

            #check whether this stage is controlled by a multiaxe controller (to be defined for each plugin)

            # if mutliaxes then init the controller here if Master state otherwise use external controller
            if self.settings.child(
                    'multiaxes',
                    'ismultiaxes').value() and self.settings.child(
                        'multiaxes', 'multi_status').value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this axe is a slave one'
                    )
                else:
                    self.controller = controller
            else:  #Master stage
                self.controller = "master_controller"  #any object that will control the stages

            info = "Mock stage"
            self.status.info = info
            self.status.controller = self.controller
            self.status.initialized = True
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
示例#2
0
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector updating the status dictionnary.

            See Also
            --------
            set_Mock_data, daq_utils.ThreadCommand
        """
        self.status.update(edict(initialized=False,info="",x_axis=None,y_axis=None,controller=None))
        try:

            if self.settings.child(('controller_status')).value()=="Slave":
                if controller is None: 
                    raise Exception('no controller has been defined externally while this detector is a slave one')
                else:
                    self.controller=controller
            else:
                self.controller="Mock controller"
            self.set_x_axis()
            self.set_Mock_data()

            # initialize viewers with the future type of data
            self.data_grabed_signal_temp.emit([OrderedDict(name='Mock1', data=self.data_mock, type='Data1D',
                x_axis= self.x_axis, labels=['Mock1', 'label2']),])

            self.status.initialized=True
            self.status.controller=self.controller
            self.status.x_axis = self.x_axis
            return self.status

        except Exception as e:
            self.emit_status(ThreadCommand('Update_Status',[getLineInfo()+ str(e),'log']))
            self.status.info=getLineInfo()+ str(e)
            self.status.initialized=False
            return self.status
    def commit_settings(self, param):
        """
        """
        if param.name() == "int_time":
            self.controller.set_config(int_time=param.value())
        elif param.name() == "x_timing":
            self.controller.set_config(x_timing=param.value())
        elif param.name() == "x_smooth":
            self.controller.window_width = param.value()
        elif param.name() == "scans_to_avg":
            self.controller.set_config(scans_to_avg=param.value())
        elif param.name() == "irradiance_on":
            if param.value():  # calibrated
                self.calib_on = True
            else:
                self.calib_on = False

        elif param.name() == "cal_path":
            self.do_irradiance_calibration()

        elif param.name() == "take_snap":
            try:
                self.snapshot = self.parent.datas[0]['data'][
                    0]  # Get currently displayed data
                self.settings.child("take_snap").setValue(False)

            except Exception as e:
                self.emit_status(
                    ThreadCommand("Update_Status",
                                  [getLineInfo() + str(e), "log"]))
                self.status.info = getLineInfo() + str(e)

        elif param.name() == "clear_snap":
            self.snapshot = None
            self.settings.child("clear_snap").setValue(False)
示例#4
0
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector with Picoscope 5000A profile.

            See Also
            --------
            daq_utils.ThreadCommand, update_pico_settings
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:
            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.pico = controller
                    try:
                        self.pico.stop()
                        status = self.pico.close_unit()
                    except:
                        pass

            else:
                self.pico = picoscope.Picoscope_5000A()

            status = self.pico.open_unit(
                None,
                dynamic_range=picoscope.DAQ_Picoscope_dynamic[
                    self.settings.child('main_settings',
                                        'dynamic').value()].value)

            if status[0] == "PICO_OK":
                self.update_pico_settings()

                self.pico.overflow_signal.connect(self.set_overflow)

                self.status.initialized = True
                self.status.controller = self.pico
                return self.status
            else:
                #self.emit_status(ThreadCommand('Update_Status',[status[0],'log']))
                self.status.info = status[0]
                self.status.initialized = False
                return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector.

            Returns
            -------

                The initialized status.

            See Also
            --------
            daq_utils.ThreadCommand
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:

            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.controller = controller
            else:
                self.controller = self.VISA_rm.open_resource(
                    self.settings.child(('VISA_ressources')).value(),
                    read_termination='\r')

            self.controller.timeout = self.settings.child(('timeout')).value()

            self.controller.write("*rst; status:preset; *cls;")
            txt = self.controller.query('*IDN?')
            self.settings.child(('id')).setValue(txt)
            self.controller.write(
                'CONF:' + self.settings.child('config', 'meas_type').value())
            self.controller.write(':FORM:ELEM READ;DATA ASC;')
            self.controller.write('ARM:SOUR IMM;')
            self.controller.write('ARM:COUNt 1;')
            self.controller.write('TRIG:SOUR IMM;')
            #%%
            data = self.controller.query_ascii_values('READ?')

            self.status.initialized = True
            self.status.controller = self.controller
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
示例#6
0
    def ini_detector(self, controller=None):
        """Detector communication initialization

        Parameters
        ----------
        controller: (object) custom object of a PyMoDAQ plugin (Slave case). None if only one detector by controller (Master case)

        Returns
        -------
        self.status (edict): with initialization status: three fields:
            * info (str)
            * controller (object) initialized controller
            *initialized: (bool): False if initialization failed otherwise True
        """

        try:
            self.status.update(
                edict(initialized=False,
                      info="",
                      x_axis=None,
                      y_axis=None,
                      controller=None))
            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.controller = controller
            else:
                ## TODO for your custom plugin
                self.controller = python_wrapper_of_your_instrument(
                )  # any object that will control the stages
                #####################################

            ## TODO for your custom plugin
            #initialize viewers pannel with the future type of data
            self.data_grabed_signal_temp.emit([
                DataFromPlugins(name='Mock1',
                                data=[np.array([0]),
                                      np.array([0])],
                                dim='Data0D',
                                labels=['Mock1', 'label2'])
            ])
            ##############################

            self.status.info = "Whatever info you want to log"
            self.status.initialized = True
            self.status.controller = self.controller
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
示例#7
0
    def ini_stage(self, controller=None):
        """Actuator communication initialization

        Parameters
        ----------
        controller: (object) custom object of a PyMoDAQ plugin (Slave case). None if only one actuator by controller (Master case)

        Returns
        -------
        self.status (edict): with initialization status: three fields:
            * info (str)
            * controller (object) initialized controller
            *initialized: (bool): False if initialization failed otherwise True
        """

        try:
            # initialize the stage and its controller status
            # controller is an object that may be passed to other instances of DAQ_Move_Mock in case
            # of one controller controlling multiactuators (or detector)

            self.status.update(
                edict(info="", controller=None, initialized=False))

            # check whether this stage is controlled by a multiaxe controller (to be defined for each plugin)
            # if multiaxes then init the controller here if Master state otherwise use external controller
            if self.settings.child(
                    'multiaxes',
                    'ismultiaxes').value() and self.settings.child(
                        'multiaxes', 'multi_status').value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this axe is a slave one'
                    )
                else:
                    self.controller = controller
            else:  # Master stage

                self.controller = dict(ao=DAQmx(), di=DAQmx())

            self.update_tasks()

            self.emit_status(
                ThreadCommand(
                    'set_allowed_values',
                    dict(decimals=0, minimum=0, maximum=3.5, step=0.1)))

            self.status.info = "Whatever info you want to log"
            self.status.controller = self.controller
            self.status.initialized = True
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
示例#8
0
    def commit_settings(self, param):
        """
            | Activate any parameter changes on the PI_GCS2 hardware.
            |
            | Called after a param_tree_changed signal from DAQ_Move_main.

            =============== ================================ ========================
            **Parameters**  **Type**                          **Description**
            *param*         instance of pyqtgraph Parameter  The parameter to update
            =============== ================================ ========================

            See Also
            --------
            daq_utils.ThreadCommand, DAQ_Move_PI.enumerate_devices
        """
        try:
            if param.name() == 'gcs_lib':
                try:
                    self.controller.CloseConnection()
                except Exception as e:
                    self.emit_status(
                        ThreadCommand("Update_Status",
                                      [getLineInfo() + str(e), 'log']))
                self.ini_device()

            elif param.name() == 'connect_type':
                self.enumerate_devices()

            elif param.name() == 'use_joystick':
                axes = self.controller.axes
                for ind, ax in enumerate(axes):
                    try:
                        if param.value():
                            res = self.controller.JAX(1, ind + 1, ax)
                            res = self.controller.JON(ind + 1, True)
                        else:
                            self.controller.JON(ind + 1, False)
                    except Exception as e:
                        pass

                pass
            elif param.name() == 'axis_address':
                self.settings.child(('closed_loop')).setValue(
                    self.controller.qSVO(param.value())[param.value()])
                self.set_referencing(
                    self.settings.child(('axis_address')).value())

            elif param.name() == 'closed_loop':
                axe = self.settings.child(('axis_address')).value()
                if self.controller.qSVO(axe)[axe] != self.settings.child(
                    ('closed_loop')).value():
                    self.controller.SVO(axe, param.value())

        except Exception as e:
            self.emit_status(
                ThreadCommand("Update_Status",
                              [getLineInfo() + str(e), 'log']))
示例#9
0
    def ini_stage(self, controller=None):
        """Actuator communication initialization

        Parameters
        ----------
        controller: (object) custom object of a PyMoDAQ plugin (Slave case). None if only one actuator by controller (Master case)

        Returns
        -------
        self.status (edict): with initialization status: three fields:
            * info (str)
            * controller (object) initialized controller
            *initialized: (bool): False if initialization failed otherwise True
        """

        try:
            # initialize the stage and its controller status
            # controller is an object that may be passed to other instances of DAQ_Move_Mock in case
            # of one controller controlling multiactuators (or detector)

            self.status.update(
                edict(info="", controller=None, initialized=False))

            # check whether this stage is controlled by a multiaxe controller (to be defined for each plugin)
            # if multiaxes then init the controller here if Master state otherwise use external controller
            if self.settings.child(
                    'multiaxes',
                    'ismultiaxes').value() and self.settings.child(
                        'multiaxes', 'multi_status').value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this axe is a slave one'
                    )
                else:
                    self.controller = controller
            else:  # Master stage
                self.controller = ActuatorWrapperWithTau()
                ## TODO for your custom plugin

                comport = self.settings.child('comport').value()

                self.controller.open_communication(
                    comport)  # any object that will control the stages
                #####################################

            self.status.info = "Controller initialized"
            self.status.controller = self.controller
            self.status.initialized = True
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector.

            Returns
            -------

                The initialized status.

            See Also
            --------
            daq_utils.ThreadCommand
        """
        self.status.update(edict(initialized=False, info="", x_axis=None, y_axis=None, controller=None))
        try:

            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception('no controller has been defined externally while this detector is a slave one')
                else:
                    self.controller = controller
            else:
                self.controller = AmplitudeSystemsCRC16()
                self.controller.init_communication(self.settings.child(('com_port')).value())
            self.settings.child(('timeout')).setValue(self.controller.timeout)

            try:
                self.settings.child(('serial_number')).setValue(self.controller.get_sn())
                QThread.msleep(200)
            except Exception as e:
                logger.exception(str(e))
            try:
                self.settings.child(('version')).setValue(self.controller.get_version())
                QThread.msleep(200)
            except Exception as e:
                logger.exception(str(e))

            self.update_status()
            for stat in self.controller.status:
                self.settings.child('status', f'stat_{stat["id"]}').setValue(stat['value'])

            self.update_all_diags()

            self.status_timer = QTimer()
            self.status_timer.timeout.connect(self.update_status)
            self.status_timer.start(1000)

            self.status.controller = self.controller
            self.status.initialized = True
            return self.status

        except Exception as e:
            self.emit_status(ThreadCommand('Update_Status', [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
示例#11
0
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector.

            Returns
            -------

                The initialized status.

            See Also
            --------
            daq_utils.ThreadCommand
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:

            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.controller = controller
            else:
                self.controller = self.VISA_rm.open_resource(
                    self.settings.child(('VISA_ressources')).value())

            self.controller.timeout = self.settings.child(('timeout')).value()
            idn = self.controller.query('OUTX1;*IDN?;')
            idn = idn.rstrip('\n')
            idn = idn.rsplit(',')
            if len(idn) >= 0:
                self.settings.child(('manufacturer')).setValue(idn[0])
            if len(idn) >= 1:
                self.settings.child(('model')).setValue(idn[1])
            if len(idn) >= 2:
                self.settings.child(('serial_number')).setValue(idn[2])

            #self.reset()

            self.status.controller = self.controller
            self.status.initialized = True
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector.

            Returns
            -------

                The initialized status.

            See Also
            --------
            daq_utils.ThreadCommand
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:

            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.controller = controller
            else:
                self.controller = self.VISA_rm.open_resource(
                    self.settings.child(('VISA_ressources')).value(),
                    read_termination='\n')

            txt = self.controller.query('*IDN?')
            self.settings.child(('id')).setValue(txt)
            Nchannels = self.number_of_channel()
            if Nchannels == 2:
                self.settings.child(('channels')).setValue(
                    dict(all_items=['CH1', 'CH2'], selected=['CH1']))
            else:
                self.settings.child(('channels')).setValue(
                    dict(all_items=['CH1', 'CH2', 'CH3', 'CH4'],
                         selected=['CH1']))

            self.status.initialized = True
            self.status.controller = self.controller
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
示例#13
0
    def init_connection(self, extra_commands=[]):
        # %%
        try:
            # create an INET, STREAMing socket
            self.socket = Socket(
                socket.socket(socket.AF_INET, socket.SOCK_STREAM))
            # now connect to the web server on port 80 - the normal http port
            self.socket.connect((self.ipaddress, self.port))
            self.cmd_signal.emit(ThreadCommand('connected'))
            self.socket.send_string(self.client_type)

            self.send_infos_xml(
                pymodaq.daq_utils.parameter.ioxml.parameter_to_xml_string(
                    self.settings))
            for command in extra_commands:
                if isinstance(command, ThreadCommand):
                    self.cmd_signal.emit(command)
            self.connected = True
            # %%

            while True:
                try:
                    ready_to_read, ready_to_write, in_error = \
                        select.select([self.socket.socket], [self.socket.socket], [self.socket.socket], 0)

                    if len(ready_to_read) != 0:
                        message = self.socket.get_string()
                        # print(message)
                        self.get_data(message)

                    if len(in_error) != 0:
                        self.connected = False
                        self.cmd_signal.emit(ThreadCommand('disconnected'))

                    QtWidgets.QApplication.processEvents()

                except Exception as e:
                    try:
                        self.cmd_signal.emit(
                            ThreadCommand('Update_Status',
                                          [getLineInfo() + str(e), 'log']))
                        self.socket.send_string('Quit')
                        self.socket.close()
                    except Exception:
                        pass
                    finally:
                        break

        except ConnectionRefusedError as e:
            self.connected = False
            self.cmd_signal.emit(ThreadCommand('disconnected'))
            self.cmd_signal.emit(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
    def ini_stage(self, controller=None):
        """
            Initialize the controller and stages (axes) with given parameters.
            See Also
            --------
            DAQ_Move_PI.set_referencing, daq_utils.ThreadCommand
        """

        try:
            device = ""
            # initialize the stage and its controller status
            # controller is an object that may be passed to other instances of DAQ_Move_Mock in case
            # of one controller controlling multiaxes

            self.status.update(
                edict(info="", controller=None, initialized=False))

            #check whether this stage is controlled by a multiaxe controller (to be defined for each plugin)

            # if mutliaxes then init the controller here if Master state otherwise use external controller
            if self.settings.child(
                    'multiaxes',
                    'ismultiaxes').value() and self.settings.child(
                        'multiaxes', 'multi_status').value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this axe is a slave one'
                    )
                else:
                    self.controller = controller
            else:  #Master stage
                self.controller = MMC_Wrapper(
                    com_port=self.settings.child('com_port').value())
                self.controller.open()
                devices = self.enumerate_devices()
                self.controller.MMC_select(devices[0])

            self.check_position()

            self.status.controller = self.controller
            self.status.info = ""
            self.status.controller = self.controller
            self.status.initialized = True
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector.

            Returns
            -------

                The initialized status.

            See Also
            --------
            daq_utils.ThreadCommand
        """
        self.status.update(edict(initialized=False, info="", x_axis=None, y_axis=None, controller=None))
        try:

            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None: 
                    raise Exception('no controller has been defined externally while this detector is a slave one')
                else:
                    self.controller = controller
            else:
                self.Device.DeviceManagerCLI.BuildDeviceList()
                serialnumbers = self.Device.DeviceManagerCLI.GetDeviceList(self.PosAligner.KCubePositionAligner.DevicePrefix)
                ser_bool = self.settings.child(('serial_number')).value() in serialnumbers
                if ser_bool:
                    self.controller = self.PosAligner.KCubePositionAligner.CreateKCubePositionAligner(
                        self.settings.child(('serial_number')).value())
                    self.controller.Connect(self.settings.child(('serial_number')).value())
                    if not self.controller.IsSettingsInitialized():
                        self.controller.WaitForSettingsInitialized(5000)
                    self.controller.StartPolling(self.settings.child(('polling_time')).value())
                    self.emit_status(ThreadCommand('update_main_settings', [['wait_time'],
                                                            self.settings.child(('polling_time')).value(), 'value']))
                    QThread.msleep(500)
                    self.controller.EnableDevice()
                    QThread.msleep(500)
                    deviceInfo = self.controller.GetDeviceInfo()
                    self.settings.child(('device_name')).setValue(deviceInfo.Name)

                else:
                    raise Exception("Not valid serial number")

            self.status.initialized = True
            self.status.controller = self.controller
            return self.status

        except Exception as e:
            self.emit_status(ThreadCommand('Update_Status', [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
示例#16
0
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector.

            Returns
            -------

                The initialized status.

            See Also
            --------
            daq_utils.ThreadCommand
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:

            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.inst = controller
            else:
                self.inst = self.VISA_rm.open_resource(
                    self.settings.child(('VISA_ressources')).value())

            self.inst.timeout = self.settings.child(('timeout')).value()
            self.settings.child(
                ('manufacturer')).setValue(self.inst.manufacturer_name)
            self.settings.child(
                ('serial_number')).setValue(self.inst.serial_number)
            self.settings.child(('model')).setValue(self.query_string('ID')[2])

            self.settings.child('config', 'mode').setValue(
                ReferenceModes(int(self.query_string('REFMODE')[2])).name)
            self.status.controller = self.inst
            self.status.initialized = True
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def __init__(self,parent=None,params_state=None):
        super(DAQ_Move_Kinesis_Flipper,self).__init__(parent,params_state)
        self.settings.child(('epsilon')).setValue(1)
        self.settings.child('bounds','is_bounds').setValue(True)
        self.settings.child('bounds','max_bound').setValue(1)
        self.settings.child('bounds','min_bound').setValue(0)

        try:
            #Kinesis_path=os.environ['Kinesis'] #environement variable pointing to 'C:\\Program Files\\Thorlabs\\Kinesis'
            #to be adjusted on the different computers
            self.move_done_action=self.Action[self.UInt64](self.move_done)

        except Exception as e:
            self.emit_status(ThreadCommand("Update_Status",[getLineInfo()+ str(e),'log']))
            raise Exception(getLineInfo()+ str(e))
示例#18
0
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector initializing the status dictionnary.

            See Also
            --------
            DAQ_utils.ThreadCommand, get_xaxis, get_yaxis
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:

            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.controller = controller
            else:
                self.controller = cv2.VideoCapture(
                    self.settings.child(('camera_index')).value())

            self.controller.set(OpenCVProp['CV_CAP_PROP_AUTO_EXPOSURE'].value,
                                1)
            self.get_active_properties(
            )  #to add settable settings to the param list (but driver builtin settings window is prefered (OpenCVProp['CV_CAP_PROP_SETTINGS'])

            self.x_axis = self.get_xaxis()
            self.y_axis = self.get_yaxis()

            self.status.x_axis = self.x_axis
            self.status.y_axis = self.y_axis
            self.status.initialized = True
            self.status.controller = self.controller
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def ini_detector(self, controller=None):
        """Detector communication initialization

        Parameters
        ----------
        controller: (object) custom object of a PyMoDAQ plugin (Slave case). None if only one detector by controller (Master case)

        Returns
        -------
        self.status (edict): with initialization status: three fields:
            * info (str)
            * controller (object) initialized controller
            *initialized: (bool): False if initialization failed otherwise True
        """

        try:
            self.status.update(
                edict(initialized=False,
                      info="",
                      x_axis=None,
                      y_axis=None,
                      controller=None))
            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.controller = controller
            else:

                self.controller = dict(ai=DAQmx())
                #####################################

            self.update_tasks()

            self.status.info = "Current measurement ready"
            self.status.initialized = True
            self.status.controller = self.controller
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector initializing the status dictionnary.

            See Also
            --------
            daq_utils.ThreadCommand, get_xaxis, get_yaxis
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:

            if self.settings.child(('controller_status')).value() == "Slave":
                if controller is None:
                    raise Exception(
                        'no controller has been defined externally while this detector is a slave one'
                    )
                else:
                    self.controller = controller
            else:
                self.controller = "Mock controller"

            self.set_Mock_data()
            # initialize viewers with the future type of data
            self.data_grabed_signal_temp.emit([
                DataFromPlugins(name='MockND',
                                data=[np.zeros((128, 30, 10))],
                                dim='DataND',
                                nav_axes=(0, 1)),
            ])

            self.status.x_axis = self.x_axis
            self.status.y_axis = self.y_axis
            self.status.initialized = True
            self.status.controller = self.controller
            return self.status

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector updating the status dictionnary.

            See Also
            --------
            set_Mock_data, daq_utils.ThreadCommand
        """
        self.status.update(edict(initialized=False,info="",x_axis=None,y_axis=None,controller=None))
        try:

            if self.settings.child(('controller_status')).value()=="Slave":
                if controller is None: 
                    raise Exception('no controller has been defined externally while this detector is a slave one')
                else:
                    self.controller=controller
            else:
                self.controller="Mock controller"



            self.set_Mock_data()

            x_axis = np.linspace(0, 10, 11)
            y_axis = np.linspace(0, 10, 11)

            self.data = np.zeros((len(x_axis), len(y_axis), len(self.signal_axis)))
            #self.data_ptr = self.data.ctypes.data_as()

            # initialize viewers with the future type of data
            self.data_grabed_signal_temp.emit([OrderedDict(name='Mock1', nav_axes=[0, 1] ,
                                data=self.data, type='DataND',
                nav_x_axis= x_axis, nav_y_axis= y_axis, labels=['Mock1'],
                                               x_axis = self.signal_axis)])

            QtWidgets.QApplication.processEvents()

            self.emit_status(ThreadCommand('show_scanner'))
            self.status.initialized=True
            self.status.controller=self.controller
            self.status.x_axis = self.x_axis
            return self.status

        except Exception as e:
            self.emit_status(ThreadCommand('Update_Status',[getLineInfo()+ str(e),'log']))
            self.status.info=getLineInfo()+ str(e)
            self.status.initialized=False
            return self.status
示例#22
0
    def commit_settings(self, param):
        """
            Activate parameters changes on the hardware.

            =============== ================================ ===========================
            **Parameters**   **Type**                          **Description**
            *param*          instance of pyqtgraph Parameter   the parameter to activate
            =============== ================================ ===========================

            See Also
            --------
            set_Mock_data
        """
        try:
            if param.name() in custom_tree.iter_children(
                    self.settings.child(('cam_settings')), []):

                self.stop()
                while self.controller.is_acquiring_images:
                    self.stop()
                    QtWidgets.QApplication.processEvents()

                feature = self.controller.device.node_map.get_node(
                    param.name())
                interface_type = feature.node.principal_interface_type
                if interface_type == EInterfaceType.intfIInteger:
                    val = int((param.value() // param.opts['step']) *
                              param.opts['step'])
                else:
                    val = param.value()
                feature.value = val  #set the desired value
                param.setValue(feature.value)  # retrieve the actually set one

                #self.update_features()

                if param.name() in ['Height', 'Width', 'OffsetX', 'OffsetY']:
                    if param.name() in ['Height', 'Width'
                                        ] and not self.settings.child(
                                            'ROIselect', 'use_ROI').value():
                        self.width = self.controller.device.node_map.get_node(
                            'Width').value
                        self.height = self.controller.device.node_map.get_node(
                            'Height').value

                        self.data = np.zeros((self.height, self.width))

            if param.name() in custom_tree.iter_children(
                    self.settings.child(('ROIselect')), []):

                while self.controller.is_acquiring_images:
                    QThread.msleep(50)
                    self.stop()
                    QtWidgets.QApplication.processEvents()

                self.set_ROI()

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
示例#23
0
    def ini_stage(self, controller=None):
        """
            | Initialisation procedure of the detector updating the status dictionnary.
            |
            | Init axes from image , here returns only None values (to tricky to di it with the server and not really necessary for images anyway)

            See Also
            --------
            utility_classes.DAQ_TCP_server.init_server, get_xaxis, get_yaxis
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:
            self.settings.child(('infos')).addChildren(self.params_client)

            self.init_server()

            self.status.info = 'TCP Server actuator'
            self.status.initialized = True
            self.status.controller = self.serversocket
            return self.status

        except Exception as e:
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
示例#24
0
    def update_viewer_data(self, posx=0, posy=0):
        """
            |PyQt5 slot triggered by the crosshair signal from the 1D or 2D Navigator
            | Update the viewer informations from an x/y given position and store data.
        Parameters
        ----------
        posx: (float) from the 1D or 2D Navigator crosshair or from one of the navigation axis viewer (in that case
            nav_axis tells from wich navigation axis the position comes from)
        posy: (float) from the 2D Navigator crosshair
        nav_axis: (int) index of the navigation axis from where posx comes from

        """
        if self.datas is not None:
            try:
                nav_axes = self.get_selected_axes()
                # datas_transposed=self.update_data_signal(self.datas)
                if len(nav_axes) == 0:
                    data = self.datas.data

                elif len(nav_axes) == 1:
                    if posx < nav_axes[0]['data'][0] or posx > nav_axes[0]['data'][-1]:
                        return
                    ind_x = utils.find_index(nav_axes[0]['data'], posx)[0][0]
                    data = self.datas.inav[ind_x].data
                elif len(nav_axes) == 2:
                    if posx < nav_axes[0]['data'][0] or posx > nav_axes[0]['data'][-1]:
                        return
                    if posy < nav_axes[1]['data'][0] or posy > nav_axes[1]['data'][-1]:
                        return
                    ind_x = utils.find_index(nav_axes[0]['data'], posx)[0][0]
                    ind_y = utils.find_index(nav_axes[1]['data'], posy)[0][0]
                    data = self.datas.inav[ind_x, ind_y].data

                else:
                    pos = []
                    for ind_view, view in enumerate(self.nav_axes_viewers):
                        p = view.roi_line.getPos()[0]
                        if p < 0 or p > len(nav_axes[ind_view]['data']):
                            return
                        ind = int(np.rint(p))
                        pos.append(ind)
                    data = self.datas.inav.__getitem__(pos).data


                if len(self.datas.axes_manager.signal_shape) == 0:  # means 0D data, plot on 1D viewer
                    self.data_buffer.extend(data)
                    self.ui.viewer1D.show_data([self.data_buffer])

                elif len(self.datas.axes_manager.signal_shape) == 1:  # means 1D data, plot on 1D viewer
                    self.ui.viewer1D.remove_plots()
                    self.ui.viewer1D.x_axis = self.x_axis
                    self.ui.viewer1D.show_data([data])

                elif len(self.datas.axes_manager.signal_shape) == 2:  # means 2D data, plot on 2D viewer
                    self.ui.viewer2D.x_axis = self.x_axis
                    self.ui.viewer2D.y_axis = self.y_axis
                    self.ui.viewer2D.setImage(data)
            except Exception as e:
                logger.exception(str(e))
                self.update_status(utils.getLineInfo() + str(e), wait_time=self.wait_time, log='log')
    def grab_data(self, Naverage=1, **kwargs):
        """

        """
        try:
            datas = []
            for ind_spectro in range(len(self.spectro_names)):
                if self.settings.child('spectrometers',
                                       'spectro{:d}'.format(ind_spectro),
                                       'grab').value():
                    self.controller.setScansToAverage(ind_spectro, Naverage)
                    data_chelou = self.controller.getSpectrum(ind_spectro)
                    data = np.array(
                        [data_chelou[ind] for ind in range(len(data_chelou))])
                    datas.append(
                        DataFromPlugins(name=self.spectro_names[ind_spectro],
                                        data=[data],
                                        dim='Data1D'))
                    QtWidgets.QApplication.processEvents()

            self.data_grabed_signal.emit(datas)

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), "log"]))
    def commit_settings(self, param):
        """
            Activate parameters changes on the hardware.

            =============== ================================ ===========================
            **Parameters**   **Type**                          **Description**
            *param*          instance of pyqtgraph Parameter   the parameter to activate
            =============== ================================ ===========================

            See Also
            --------
            set_Mock_data
        """
        try:
            if param.parent().name() == 'cam_settings':
                getattr(self.controller, param.name()).value = param.value()
                param.setValue(getattr(self.controller, param.name()).value)
            elif param.name() == 'video_formats':
                self.controller.stop_live()
                self.controller.set_video_format(param.value().encode())
                # if 'Y' in param.value():
                #     self.controller.set_format(0)
                # else:
                #     self.controller.set_format(1)
                self.controller.start_live()
        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
示例#27
0
    def list_2Dscans(self):
        try:
            scans = utils.get_h5file_scans(self.h5file)
            #settings=[dict(scan_name=node._v_name,path=node._v_pathname, pixmap=nparray2Qpixmap(node.read()))),...]
            params = []
            for child in self.settings.child(('scans')).children():
                if 'Scan' in child.name():
                    self.settings.child(('scans')).removeChild(child)
            for scan in scans:
                params.append({
                    'name':
                    scan['scan_name'],
                    'type':
                    'pixmap_check',
                    'value':
                    dict(data=scan['data'], checked=False, path=scan['path'])
                })
            self.settings.child(('scans')).addChildren(params)

            for child in self.settings.child(('scans')).children():
                val = child.value()
                val.update(dict(checked=True))
                child.setValue(val)
                child.sigValueChanged.emit(child, child.value())

        except Exception as e:
            self.update_status(utils.getLineInfo() + str(e),
                               status_time=self.status_time,
                               log_type='log')
    def timerEvent(self, event):
        """
            | Called by set timers (only one for this self).
            | 
            =============== ==================== ==============================================
            **Parameters**    **Type**             **Description**

            *event*           QTimerEvent object   Containing id from timer issuing this event
            =============== ==================== ==============================================
        """
        try:
            #this is used to update image area if any call of the controller within multiple instance has been triggered and image size has been changed
            sizex, sizey = self.controller.getImageSize()
            if sizex != self.settings.child('pixels_settings','Nx').value() or sizey != self.settings.child('pixels_settings','Ny').value():
                #try:
                #    self.settings.sigTreeStateChanged.disconnect(self.send_param_status)
                #except: pass
                self.controller.setImageSize(sizex,sizey)
                self.controller.setImageArea(sizex, sizey, 0, sizex, 0, sizey)
                self.settings.child('pixels_settings','Nx').setValue(sizex)
                self.settings.child('pixels_settings','Ny').setValue(sizey)

                if self.settings.child('multiaxes','axis').value()==self.stage_names[0]:
                    self.settings.child('bounds','max_bound').setValue(sizex-1)
                else:
                    self.settings.child('bounds','max_bound').setValue(sizey-1)

                #self.settings.sigTreeStateChanged.connect(self.send_param_status)
        except Exception as e:
            self.emit_status(ThreadCommand('Update_Status',[getLineInfo()+ str(e),"log"]))
    def ini_detector(self, controller=None):
        """
            See Also
            --------
            DAQ_utils.ThreadCommand, hardware1D.DAQ_1DViewer_Picoscope.update_pico_settings
        """
        self.status.update(
            edict(initialized=False,
                  info="",
                  x_axis=None,
                  y_axis=None,
                  controller=None))
        try:
            self.status = super(DAQ_2DViewer_FLIM,
                                self).ini_detector(controller)

            self.ini_stage()
            self.status.x_axis = self.x_axis
            self.status.initialized = True
            self.status.controller = self.controller

            return self.status

        except Exception as e:
            self.status.info = getLineInfo() + str(e)
            self.status.initialized = False
            return self.status
    def emit_data(self):
        """
        """
        try:
            mode = self.settings.child('acquisition', 'acq_type').value()
            if mode == 'Counting' or mode == 'Histo' or mode == 'T3':
                super(DAQ_2DViewer_FLIM, self).emit_data()

            elif mode == 'FLIM':
                self.stop_scanner.emit()
                self.h5saver.h5_file.flush()
                datas = self.process_histo_from_h5_and_correct_shifts(
                    self.Nx, self.Ny, channel=0, marker=65)
                self.data_grabed_signal.emit([
                    DataFromPlugins(name='TH260',
                                    data=datas,
                                    dim='DataND',
                                    nav_axes=(0, 1),
                                    nav_x_axis=self.get_nav_xaxis(),
                                    nav_y_axis=self.get_nav_yaxis(),
                                    xaxis=self.get_xaxis(),
                                    external_h5=self.h5saver.h5_file)
                ])
                self.stop()

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))