pyrtma.Client
- class Client(module_id=0, host_id=0, timecode=False)[source]
Bases:
object
RTMA Client interface
- Parameters:
module_id (optional) – Static module ID, which must be unique. Defaults to 0, which generates a dynamic module ID.
host_id (optional) – Host ID. Defaults to 0.
timecode (optional) – Add additional timecode fields to message header, used by some projects at RNEL. Defaults to False.
Methods
Connect to message manager server
Read and discard messages in socket buffer up to timeout
Disconnect from message manager server
Forward a message
Pause all subscribed types
Pause subscription to message types
Context manager to pause subscriptions to a list of message types
Read a message
Resume all paused subscriptions
Resume subscription to message types
Send a message
Send a signal to message manager that client is ready
Send a signal
Subscribe to message types
Context manager to subscribe to a list of message types
Unsubscribe from message types
Unsubscribe from all subscribed types
Attributes
Status of connection to message manager server
Class defining the RTMA message header
Message manager IP address string
Numeric module ID of client
Count of messages that have been sent
Subscriptions on pause
Message manager port number
Message manager server address as a (IP_addr, port_num) tuple
Underlying socket connection with MessageManager
List of subscribed message types
- connect(server_name='localhost:7111', logger_status=False, daemon_status=False)[source]
Connect to message manager server
- Parameters:
server_name (optional) – IP_addr:port_num string associated with message manager. Defaults to “localhost:7111”.
logger_status (optional) – Flag to declare client as a logger module. Logger modules are automatically subscribed to all message types. Defaults to False.
daemon_status (optional) – Flag to declare client as a daemon. Defaults to False.
- Raises:
MessageManagerNotFound – Unable to connect to message manager
- discard_messages(timeout=1)[source]
Read and discard messages in socket buffer up to timeout
- Parameters:
timeout (optional) – Maximum time in seconds to loop through message buffer. Defaults to 1.
- Return type:
- Returns:
True if all messages have been read, False if messages remain in buffer
- forward_message(msg_hdr, msg_data=None, timeout=-1)[source]
Forward a message
A message is a packet that contains a defined data payload. To send a message without associated data, see
send_signal()
.- Parameters:
msg_hdr (
MessageHeader
) – Object containing RTMA header to sendmsg_data (
Optional
[MessageData
]) – Object containing the message to sendtimeout (optional) – Timeout in seconds to wait for socket to be available for sending. Defaults to -1 (blocking).
- property header_cls: Type[MessageHeader]
Class defining the RTMA message header
- pause_subscription(msg_list)[source]
Pause subscription to message types
- Parameters:
msg_list (Iterable[int]) – A list of numeric message IDs to temporarily unsubscribe to
- paused_subscription_context(msg_list)[source]
Context manager to pause subscriptions to a list of message types
Message types will automatically resume subscriptions after exiting context.
- Parameters:
msg_list (Iterable[int]) – A list of numeric message IDs to temporarily unsubscribe to
- read_message(timeout=-1, ack=False, sync_check=False)[source]
Read a message
- Parameters:
timeout (optional) – Timeout to wait for a message to be available for reading. Defaults to -1 (blocking).
ack (optional) – Primarily for internal use. When True, will not discard ACK messages. Defaults to False.
sync_check (optional) – Validate message definition matches header version. Defaults to False.
- Raises:
ConnectionLost – Connection error to message manager server
- Return type:
- Returns:
Message object. If no message is read before timeout, returns None.
- resume_subscription(msg_list)[source]
Resume subscription to message types
- Parameters:
msg_list (Iterable[int]) – A list of paused message IDs to resubscribe to
- send_message(msg_data, dest_mod_id=0, dest_host_id=0, timeout=-1)[source]
Send a message
A message is a packet that contains a defined data payload. To send a message without associated data, see
send_signal()
.- Parameters:
msg_data (
MessageData
) – Object containing the message to senddest_mod_id (optional) – Specific module ID to send to. Defaults to 0 (broadcast).
dest_host_id (optional) – Specific host ID to send to. Defaults to 0 (broadcast).
timeout (optional) – Timeout in seconds to wait for socket to be available for sending. Defaults to -1 (blocking).
- Raises:
InvalidDestinationModule – Specified destination module is invalid
InvalidDestinationHost – Specified destination host is invalid
- send_module_ready()[source]
Send a signal to message manager that client is ready
This method also sends the client’s process ID to message manager.
- send_signal(signal_type, dest_mod_id=0, dest_host_id=0, timeout=-1)[source]
Send a signal
A signal is a message type without an associated data payload. Only a unique message type ID is required to send a signal. To send a message with data, see
send_message()
.- Parameters:
signal_type (
int
) – Numeric message type ID of signaldest_mod_id (optional) – Specific module ID to send to. Defaults to 0 (broadcast).
dest_host_id (optional) – Specific host ID to send to. Defaults to 0 (broadcast).
timeout (optional) – Timeout in seconds to wait for socket to be available for sending. Defaults to -1 (blocking).
- Raises:
InvalidDestinationModule – Specified destination module is invalid
InvalidDestinationHost – Specified destination host is invalid
- subscribe(msg_list)[source]
Subscribe to message types
Calling this method multiple times will add to, and not replace, the list of subscribed messages.
- Parameters:
msg_list (Iterable[int]) – A list of numeric message IDs to subscribe to
- subscription_context(msg_list)[source]
Context manager to subscribe to a list of message types
Message types will automatically unsubscribe after exiting context.
- Parameters:
msg_list (Iterable[int]) – A list of numeric message IDs to subscribe to