Esempio n. 1
0
    def read_info(self, sock, dtype=np.float64):
        """
        """
        try:

            ##first get the info type
            length_bytes = check_received_length(sock, 4)
            length = np.frombuffer(
                length_bytes,
                dtype='>i4')[0]  # big endian 4 bytes==uint32 swaped
            message = check_received_length(sock, length).decode()

            # get data length
            length_bytes = check_received_length(sock, 4)
            length = np.frombuffer(length_bytes, dtype='>i4')[0]

            ##then get data
            data_bytes = check_received_length(sock, length)

            data = np.frombuffer(data_bytes, dtype=dtype)
            data = data.newbyteorder()[0]  # convert it to big endian
            try:
                self.settings.child('infos', message).setValue(data)
            except Exception as e:
                self.emit_status(
                    ThreadCommand('Update_Status', [str(e), 'log']))

        except Exception as e:
            data = 0

        return data
Esempio n. 2
0
 def read_infos(self, sock):
     length_bytes = check_received_length(sock, 4)
     length = np.frombuffer(length_bytes, dtype='>i4')[0]  # big endian 4 bytes==uint32 swaped
     infos = check_received_length(sock, length).decode()
     params = custom_tree.XML_string_to_parameter(infos)
     param_state = {'title': 'Infos Client:', 'name': 'infos', 'type': 'group', 'children': params}
     self.settings.child(('infos')).restoreState(param_state)
Esempio n. 3
0
    def process_cmds(self, command, command_sock=None):
        """
            Process the given command.

            Depending on the command name :
            * Done :

                * Find a socket from the 'GRABBER' connected client.
                * Send data to a viewer or a client (depending on command_sock).

            * Info : Find a socket from the 'GRABBER' connected client and read infos.

            * Send Data 0D :

                * Find a socket from the 'GRABBER' connected client.
                * set a 1D Mock data.

            * Send Data 1D :

                * Find a socket from the 'GRABBER' connected client.
                * set a 1D Mock data.

            * Send Data 2D :

                * Find a socket from the 'GRABBER' connected client.
                * set a 2D Mock data.

            =============== =========== ==========================
            **Parameters**    **Type**    **Description**
            *command*         string      the command as a string
            *command_sock*    ???
            =============== =========== ==========================

            See Also
            --------
            find_socket_within_connected_clients, read_data, send_data, utility_classes.DAQ_Viewer_base.emit_status, daq_utils.ThreadCommand, send_command, set_1D_Mock_data, set_2D_Mock_data, process_cmds
        """
        if command not in self.message_list:
            return

        if command == 'Done':  # means the given socket finished grabbing data and is ready to send them
            self.command_done(command_sock)

        elif command == "Infos":
            try:
                sock = self.find_socket_within_connected_clients(
                    self.client_type)
                if sock is not None:  # if client self.client_type is connected then send it the command
                    self.read_infos(sock)

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

        elif command == "Info":
            try:
                sock = self.find_socket_within_connected_clients(
                    self.client_type)
                if sock is not None:  # if client self.client_type is connected then send it the command
                    self.read_info(sock)
            except Exception as e:
                self.emit_status(
                    ThreadCommand("Update_Status", [str(e), 'log']))

        elif command == 'Info_xml':
            sock = self.find_socket_within_connected_clients(self.client_type)
            if sock is not None:
                list_len = get_int(sock)
                path = []
                for ind in range(list_len):
                    data_len = int.from_bytes(check_received_length(sock, 4),
                                              'big')
                    path.append(check_received_length(sock, data_len).decode())
                data_len = int.from_bytes(check_received_length(sock, 4),
                                          'big')
                param_xml = check_received_length(sock, data_len).decode()
                param_dict = custom_tree.XML_string_to_parameter(param_xml)[0]

                param_here = self.settings.child('infos', *path[1:])
                param_here.restoreState(param_dict)

        else:
            self.command_to_from_client(command)