TCP/IP related methods
Serializing object to bytes and back
Created the 20/10/2023
@author: Sebastien Weber
Custom Sockets to implement PyMoDAQ protocol
Base classes as TCP server and client
Created on Fri Aug 30 12:21:56 2019
@author: Weber
- class pymodaq.utils.tcp_ip.tcp_server_client.TCPClient(ipaddress='192.168.1.62', port=6341, params_state=None, client_type='GRABBER')[source]
PyQt5 object initializing a TCP socket client. Can be used by any module but is a builtin functionality of all actuators and detectors of PyMoDAQ
The module should init TCPClient, move it in a thread and communicate with it using a custom signal connected to TCPClient.queue_command slot. The module should also connect TCPClient.cmd_signal to one of its methods inorder to get info/data back from the client
The client itself communicate with a TCP server, it is best to use a server object subclassing the TCPServer class defined within this python module
- Parameters:
params_state (
(dict) stateofthe Parameter settingsofthe module instantiating this clientandwishing to) – export its settings to the server. Obtained from param.saveState() where param is an instance of Parameter object, see pyqtgraph.parametertree::Parameter
Methods
get_data(message)post_init([extra_commands])queue_command([command])when this TCPClient object is within a thread, the corresponding module communicate with it with signal and slots from module to client: module_signal to queue_command slot from client to module: self.cmd_signal to a module slot
ready_to_read()ready_to_write()ready_with_error()cmd_signal
data_ready
not_connected
process_error_in_polling
send_data
send_info_string
send_infos_xml
- queue_command(command=<class 'pymodaq_utils.utils.ThreadCommand'>)[source]
when this TCPClient object is within a thread, the corresponding module communicate with it with signal and slots from module to client: module_signal to queue_command slot from client to module: self.cmd_signal to a module slot
- class pymodaq.utils.tcp_ip.tcp_server_client.TCPServer(client_type='GRABBER')[source]
Abstract class to be used as inherited by DAQ_Viewer_TCP or DAQ_Move_TCP
Methods
close the current opened server.
Find a socket type from a connected client with socket content corresponding.
find_socket_within_connected_clients(client_type)Find a socket from a connected client with socket type corresponding.
Server function.
print_status(status)Print the given status.
process_cmds(command[, command_sock])Process the given command.
read_info([sock, test_info, test_value])if the client is not from PyMoDAQ it can use this method to display some info into the server widget
select(rlist[, wlist, xlist, timeout])Implements the select method, https://docs.python.org/3/library/select.html :type rlist:
(list) wait until ready for reading:param rlist: :type rlist:(list) wait until ready for reading:type wlist:(list) wait until ready for writing:param wlist: :type wlist:(list) wait until ready for writing:type xlist:(list) wait for an “exceptional condition”:param xlist: :type xlist:(list) wait for an “exceptional condition”:type timeout:(float) optional timeout argument specifies a time-out as a floating point number in seconds.:param timeout: When the timeout argument is omitted the function blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks. :type timeout:(float) optional timeout argument specifies a time-out as a floating point number in seconds..send_command(sock[, command])Send one of the message contained in self.message_list toward a socket with identity socket_type.
timerEvent(event)Called by set timers.
command_done
command_to_from_client
emit_status
init_server
read_data
read_info_xml
read_infos
remove_client
send_data
set_connected_clients_table
- close_server()[source]
close the current opened server. Update the settings tree consequently.
See also
set_connected_clients_table,daq_utils.ThreadCommand
- find_socket_type_within_connected_clients(sock)[source]
Find a socket type from a connected client with socket content corresponding.
Parameters
Type
Description
sock
???
The socket content corresponding.
- Returns:
the socket dictionnary
- Return type:
dictionnary
- find_socket_within_connected_clients(client_type)[source]
Find a socket from a connected client with socket type corresponding.
Parameters
Type
Description
client_type
string
The corresponding client type
- Returns:
the socket dictionnary
- Return type:
- print_status(status)[source]
Print the given status.
Parameters
Type
Description
status
string list
a string list representing the status socket
- read_info(sock=None, test_info='an_info', test_value='')[source]
if the client is not from PyMoDAQ it can use this method to display some info into the server widget
- select(rlist, wlist=[], xlist=[], timeout=0)[source]
Implements the select method, https://docs.python.org/3/library/select.html :type rlist:
(list) wait until ready for reading:param rlist: :type rlist:(list) wait until ready for reading:type wlist:(list) wait until ready for writing:param wlist: :type wlist:(list) wait until ready for writing:type xlist:(list) wait for an “exceptional condition”:param xlist: :type xlist:(list) wait for an “exceptional condition”:type timeout:(float) optional timeout argument specifies a time-out as a floating point number in seconds.:param timeout: When the timeout argument is omitted the function blocks until at least one file descriptor is ready.A time-out value of zero specifies a poll and never blocks.
- Returns:
list (
readable sockets)list (
writable sockets)list (
sockets with error pending)
- send_command(sock, command='move_at')[source]
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