def send_command(self, sock, command="move_at"): """ Send one of the message contained in self.message_list toward a socket with identity socket_type. First send the length of the command with 4bytes. =============== =========== ========================== **Parameters** **Type** **Description** *sock* ??? The current socket *command* string The command as a string =============== =========== ========================== See Also -------- utility_classes.DAQ_Viewer_base.emit_status, daq_utils.ThreadCommand, message_to_bytes """ if command not in self.message_list: self.emit_status( ThreadCommand("Update_Status", [ 'Command: ' + str(command) + ' not in the specified list', 'log' ])) return if sock is not None: send_string(sock, command)
def move_Rel(self, position): position = self.check_bound(self.current_position + position) - self.current_position self.target_position = position + self.current_position position = self.set_position_relative_with_scaling(position) 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 send_string(sock, 'move_rel') send_scalar(sock, position)
def move_Home(self): """ Make the absolute move to original position (0). See Also -------- move_Abs """ 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 send_string(sock, 'move_home')
def move_Abs(self, position): """ """ position = self.check_bound(position) self.target_position = position position = self.set_position_with_scaling(position) 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 send_string(sock, 'move_abs') send_scalar(sock, position)
def init_connection(self): # %% try: # create an INET, STREAMing socket self.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')) send_string(self.socket, self.client_type) self.send_infos_xml( custom_tree.parameter_to_xml_string(self.settings)) self.cmd_signal.emit(ThreadCommand('get_axis')) # %% while True: try: ready_to_read, ready_to_write, in_error = \ select.select([self.socket], [self.socket], [self.socket], 0) if len(ready_to_read) != 0: message = get_string(self.socket) # print(message) self.get_data(message) if len(in_error) != 0: 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'])) send_string(self.socket, 'Quit') self.socket.close() except: pass finally: break except ConnectionRefusedError as e: self.cmd_signal.emit(ThreadCommand('disconnected')) self.cmd_signal.emit( ThreadCommand('Update_Status', [getLineInfo() + str(e), 'log']))
def commit_settings(self, param): if param.name() in custom_tree.iter_children( self.settings.child(('infos')), []): actuator_socket = [ client['socket'] for client in self.connected_clients if client['type'] == 'ACTUATOR' ][0] send_string(actuator_socket, 'set_info') path = custom_tree.get_param_path( param )[2:] #get the path of this param as a list starting at parent 'infos' send_list(actuator_socket, path) #send value data = custom_tree.parameter_to_xml_string(param) send_string(actuator_socket, data)
def queue_command(self, command=ThreadCommand()): """ """ if command.command == "ini_connection": status = self.init_connection() elif command.command == "quit": try: self.socket.close() except Exception as e: pass finally: self.cmd_signal.emit(ThreadCommand('disconnected')) elif command.command == 'update_connection': self.ipaddress = command.attributes['ipaddress'] self.port = command.attributes['port'] elif command.command == 'data_ready': self.data_ready(command.attributes) elif command.command == 'send_info': path = command.attributes['path'] param = command.attributes['param'] param_xml = custom_tree.parameter_to_xml_string(param) send_string(self.socket, 'Info_xml') send_list(self.socket, path) # send value data = custom_tree.parameter_to_xml_string(param) send_string(self.socket, data) elif command.command == 'position_is': send_string(self.socket, 'position_is') send_scalar(self.socket, command.attributes[0]) elif command.command == 'move_done': send_string(self.socket, 'move_done') send_scalar(self.socket, command.attributes[0]) elif command.command == 'x_axis': send_string(self.socket, 'x_axis') x_axis = dict(label='', units='') if isinstance(command.attributes[0], np.ndarray): x_axis['data'] = command.attributes[0] elif isinstance(command.attributes[0], dict): x_axis.update(command.attributes[0].copy()) send_array(self.socket, x_axis['data']) send_string(self.socket, x_axis['label']) send_string(self.socket, x_axis['units']) elif command.command == 'y_axis': send_string(self.socket, 'y_axis') y_axis = dict(label='', units='') if isinstance(command.attributes[0], np.ndarray): y_axis['data'] = command.attributes[0] elif isinstance(command.attributes[0], dict): y_axis.update(command.attributes[0].copy()) send_array(self.socket, y_axis['data']) send_string(self.socket, y_axis['label']) send_string(self.socket, y_axis['units'])
def send_infos_xml(self, infos): send_string(self.socket, 'Infos') send_string(self.socket, infos)
def send_data(self, data_list): # first send 'Done' and then send the length of the list send_string(self.socket, 'Done') send_list(self.socket, data_list)