Communicator¶
-
class
lsst.ts.MTMount.Communicator(name, client_host, client_port, server_host, server_port, log, read_replies, connect_client=True, connect_callback=None)¶ Bases:
lsst.ts.MTMount.ClientServerPairRead and write
BaseMessages using Tekniker’s communication protocol.Data is written to the client socket and read from the (single) server socket.
Parameters: - name :
str Name used for error messages.
- client_host :
str IP address for the output client socket.
- client_port :
int IP port for the output client socket.
- server_host :
strorNone IP address for the input socket server. If
Nonethen use all interfaces.- server_port :
int IP port for the input socket server. If 0 then use a random port.
- log :
logging.Logger Logger.
- read_replies :
bool If True then read replies, else read commands, on the server port.
- connect_client :
bool(optional) Connect the client at construction time?
- connect_callback : callable (optional)
Synchronous function to call when a connection is made or dropped.
Notes
Tekniker’s OperationManager software connects to each component (PXI, EUI and HHD) using two TCP/IP sockets:
- A client socket for output; data is only written to this socket.
- For the PXI this is used to send commands. For EUI and HDD this is used to send replies.
- A server socket for input; data is only read from this socket.
- For the PXI this is used to read replies. For EUI and HDD this is used to read commands.
Attributes Summary
client_connectedIs the client connected? connect_retry_intervalconnectedAre both the client and server connected? server_connectedIs the server connected? server_hostserver_portserver_readerServer reader, an asyncio.StreamReaderorNoneif not connected.server_writerServer writer, an asyncio.StreamWriterorNoneif not connected.Methods Summary
call_connect_callback(*args, **kwargs)Call the connect_callback if it exists. close()Close both the server and the client, to clean up when finished. close_client()Close the client. connect([port])Connect the client socket and wait for a connection to the server. monitor_client_reader()Monitor the client reader; if it closes then close the writer. read()Read and return a message. wait_server_port()Wait for the server to start, then return the port. write(message)Write a message. Attributes Documentation
-
client_connected¶ Is the client connected?
-
connect_retry_interval= 0.1¶
-
connected¶ Are both the client and server connected?
-
server_connected¶ Is the server connected?
-
server_host¶
-
server_port¶
-
server_reader¶ Server reader, an
asyncio.StreamReaderorNoneif not connected.
-
server_writer¶ Server writer, an
asyncio.StreamWriterorNoneif not connected.
Methods Documentation
-
call_connect_callback(*args, **kwargs)¶ Call the connect_callback if it exists. Any arguments are ignored.
-
close()¶ Close both the server and the client, to clean up when finished.
Set the server done_task done.
-
close_client()¶ Close the client.
Warning: does NOT call the connect_callback.
-
connect(port=None)¶ Connect the client socket and wait for a connection to the server.
Parameters: Notes
This will wait forever for a connection.
-
monitor_client_reader()¶ Monitor the client reader; if it closes then close the writer.
-
read()¶ Read and return a message. Waits indefinitely.
Returns: - message :
BaseMessage The message read.
- message :
-
wait_server_port()¶ Wait for the server to start, then return the port.
Useful when you have specified port=0, e.g. for unit tests.
-
write(message)¶ Write a message.
Parameters: - message :
BaseMessage Message to write.
- message :
- name :