def commit_settings(self, param):
        """
            Setting the mock data.

            ============== ========= =================
            **Parameters**  **Type**  **Description**
            *param*         none      not used
            ============== ========= =================

            See Also
            --------
            set_Mock_data
        """
        if param.name() == 'wait_time':
            self.emit_status(
                utils.ThreadCommand(
                    'update_main_settings',
                    [['wait_time'], param.value(), 'value']))
        elif param.name() == 'show_scanner':
            self.emit_status(
                utils.ThreadCommand('show_scanner', [param.value()]))
            QtWidgets.QApplication.processEvents()
        elif param.name() == 'show_navigator':
            self.emit_status(
                utils.ThreadCommand('show_navigator', [param.value()]))
    def ini_detector(self, controller=None):
        """
            Initialisation procedure of the detector.

            Returns
            -------
            ???
                the initialized status.

            See Also
            --------
            set_Mock_data
        """

        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 = "Mock controller"
        self.emit_status(utils.ThreadCommand('update_main_settings', [['wait_time'],
                                                                      self.settings.child(('wait_time')).value(),
                                                                      'value']))

        # initialize viewers with the future type of data
        self.data_grabed_signal.emit(
            [utils.DataFromPlugins(name='Mock1', data=[np.array(0)], dim='Data0D', labels=['RandomGaussians'])])

        self.status.initialized = True
        self.status.controller = self.controller
        return self.status
Ejemplo n.º 3
0
    def move_actuators(self, positions):
        self.move_done_positions = OrderedDict()
        self.move_done_flag = False
        self.settings.child(('move_done')).setValue(self.move_done_flag)

        if not hasattr(positions, '__iter__'):
            positions = [positions]

        if len(positions) == self.Nactuators:
            if isinstance(positions, dict):
                for k in positions:
                    act = self.get_mod_from_name(k, 'act')
                    if act is not None:
                        act.command_stage.emit(
                            utils.ThreadCommand(command="move_Abs",
                                                attributes=[positions[k]]))
            else:
                for ind, act in enumerate(self.actuators):
                    act.command_stage.emit(
                        utils.ThreadCommand(command="move_Abs",
                                            attributes=[positions[ind]]))

        else:
            logger.error(
                'Invalid number of positions compared to selected actuators')
            return self.move_done_positions

        tzero = time.perf_counter()

        while not self.move_done_flag:  #polling move done

            QtWidgets.QApplication.processEvents()
            if time.perf_counter() - tzero > self.timeout:
                self.timeout_signal.emit(True)
                logger.error(
                    'Timeout Fired during waiting for data to be acquired')
                break
            QThread.msleep(20)

        self.move_done_signal.emit(self.move_done_positions)
        return self.move_done_positions
    def commit_settings(self, param):
        """
            Setting the mock data.

            ============== ========= =================
            **Parameters**  **Type**  **Description**
            *param*         none      not used
            ============== ========= =================

            See Also
            --------
            set_Mock_data
        """
        if param.name() == 'wait_time':
            self.emit_status(utils.ThreadCommand('update_main_settings', [['wait_time'], param.value(), 'value']))
Ejemplo n.º 5
0
    def grab_datas(self, **kwargs):
        self.det_done_datas = OrderedDict()
        self.det_done_flag = False
        self.settings.child(('det_done')).setValue(self.det_done_flag)
        tzero = time.perf_counter()

        for sig in [mod.command_detector for mod in self.detectors]:
            sig.emit(utils.ThreadCommand("single", [1, kwargs]))

        while not self.det_done_flag:
            #wait for grab done signals to end

            QtWidgets.QApplication.processEvents()
            if time.perf_counter() - tzero > self.timeout:
                self.timeout_signal.emit(True)
                logger.error(
                    'Timeout Fired during waiting for data to be acquired')
                break

        self.det_done_signal.emit(self.det_done_datas)
        return self.det_done_datas
Ejemplo n.º 6
0
def test_ThreadCommand():
    command = 'abc'
    attributes = [1, 3]
    threadcomm = utils.ThreadCommand(command, attributes)
    assert threadcomm.command is command
    assert threadcomm.attributes is attributes
Ejemplo n.º 7
0
 def update_status(self, status):
     self.status_sig.emit(
         utils.ThreadCommand("Update_Status", [status, 'log']))
    def test_methods(self, qtbot):
        server = SimpleServer(('127.0.0.1', 6341), )
        server.start()

        params = [{
            'title': 'Device index:',
            'name': 'device',
            'type': 'int',
            'value': 0,
            'max': 3,
            'min': 0
        }, {
            'title': 'Infos:',
            'name': 'infos',
            'type': 'str',
            'value': "one_info",
            'readonly': True
        }, {
            'title':
            'Line Settings:',
            'name':
            'line_settings',
            'type':
            'group',
            'expanded':
            False,
            'children': [
                {
                    'name': 'someparam',
                    'type': 'float',
                    'value': 15.54,
                    'readonly': True
                },
            ]
        }]
        param = Parameter.create(name='settings',
                                 type='group',
                                 children=params)
        client = TCPClient(ipaddress="127.0.0.1",
                           port=6341,
                           params_state=param.saveState(),
                           client_type="sometype")
        client.cmd_signal.connect(self.get_cmd_signal)

        #check init method
        assert client.ipaddress == "127.0.0.1"
        assert client.port == 6341
        assert client.client_type == 'sometype'

        client.socket = Socket(
            native_socket.socket(socket.AF_INET, socket.SOCK_STREAM))
        client.socket.connect((client.ipaddress, client.port))
        sleep(0.5)
        server_socket = Socket(server.do_read()[0])

        client.send_data([np.array([0, 1, 2, 3]), 'item', 5.1])
        assert server_socket.get_string() == 'Done'
        utils.check_vals_in_iterable(server_socket.get_list(),
                                     [np.array([0, 1, 2, 3]), 'item', 5.1])

        client.send_infos_xml(custom_tree.parameter_to_xml_string(param))
        assert server_socket.get_string() == 'Infos'
        assert server_socket.get_string(
        ) == custom_tree.parameter_to_xml_string(param).decode()

        client.send_info_string('someinfo', 'this is an info')
        assert server_socket.get_string() == 'Info'
        assert server_socket.get_string() == 'someinfo'
        assert server_socket.get_string() == 'this is an info'

        #test queue_command
        client.cmd_signal.connect(self.get_cmd_signal)
        client_manager = ClientObjectManager()
        client_manager.cmd_signal.connect(client.queue_command)

        with pytest.raises(Exception):
            client.queue_command(utils.ThreadCommand('Weird command'))

        #test get_data
        server_socket.send_string('set_info')
        server_socket.send_list(['line_settings', 'someparam'])
        server_socket.send_string(
            custom_tree.parameter_to_xml_string(
                param.child('line_settings', 'someparam')))

        msg = client.socket.get_string()
        client.get_data(msg)
        assert self.command == 'set_info'
        utils.check_vals_in_iterable(
            self.attributes,
            [['line_settings', 'someparam'],
             custom_tree.parameter_to_xml_string(
                 param.child('line_settings', 'someparam')).decode()])

        server_socket.send_string('move_abs')
        server_socket.send_scalar(12.546)

        msg = client.socket.get_string()
        client.get_data(msg)
        assert self.command == 'move_abs'
        utils.check_vals_in_iterable(self.attributes, [12.546])

        server_socket.send_string('move_rel')
        server_socket.send_scalar(3.2)

        msg = client.socket.get_string()
        client.get_data(msg)
        assert self.command == 'move_rel'
        utils.check_vals_in_iterable(self.attributes, [3.2])

        server.stop()
 def get_cmd_signal(self, command=utils.ThreadCommand()):
     self.command = command.command
     self.commands.append(self.command)
     self.attributes = command.attributes
Ejemplo n.º 10
0
    def move_actuators(self, positions, mode='abs', polling=True):
        """will apply positions to each currently selected actuators. By Default the mode is absolute but can be

        Parameters
        ----------
        positions: (list) the list of position to apply. Its length must be equal to the number of selected actutors
        mode: (str) either 'abs' for absolute positionning or 'rel' for relative
        poll: (bool) if True will wait for the selected actuators to reach their target positions (they have to be
        connected to a method checking for the position and letting the programm know the move is done (default
        connection is this object `move_done` method)

        Returns
        -------
        (OrderedDict) with the selected actuators's name as key and current actuators's value as value

        See Also
        --------
        move_done
        """
        self.move_done_positions = OrderedDict()
        self.move_done_flag = False
        self.settings.child(('move_done')).setValue(self.move_done_flag)

        if mode == 'abs':
            command = 'move_Abs'
        elif mode == 'rel':
            command = 'move_Rel'
        else:
            logger.error(f'Invalid positioning mode: {mode}')
            return self.move_done_positions

        if not hasattr(positions, '__iter__'):
            positions = [positions]

        if len(positions) == self.Nactuators:
            if isinstance(positions, dict):
                for k in positions:
                    act = self.get_mod_from_name(k, 'act')
                    if act is not None:
                        act.command_stage.emit(
                            utils.ThreadCommand(
                                command=command,
                                attributes=[positions[k], polling]))
            else:
                for ind, act in enumerate(self.actuators):
                    act.command_stage.emit(
                        utils.ThreadCommand(
                            command=command,
                            attributes=[positions[ind], polling]))

        else:
            logger.error(
                'Invalid number of positions compared to selected actuators')
            return self.move_done_positions

        tzero = time.perf_counter()
        if polling:
            while not self.move_done_flag:  # polling move done

                QtWidgets.QApplication.processEvents()
                if time.perf_counter() - tzero > self.timeout:
                    self.timeout_signal.emit(True)
                    logger.error(
                        'Timeout Fired during waiting for data to be acquired')
                    break
                QThread.msleep(20)

        self.move_done_signal.emit(self.move_done_positions)
        return self.move_done_positions