Thales Connection
- class ThalesRemoteConnection
Class to handle the Thales remote connection.
- connectToTerm(address: str, connection_name: str = 'ScriptRemote') bool
Connect to the Term Software with a IP address and an optional connection name.
connection_name cannot be chosen completely freely. If you want to send Remote2 commands with the connection, then the name ScriptRemote must be used and if you want to receive the online display data, then the name Logging must be used.
- Parameters
address – hostname or ip-address of the host running “Term” application
connection_name – name of the connection. ScriptRemote for Remote2 and Logging as Online Display are fixed.
- Returns
True on success, False on failure
- getConnectionName() str
get the connection name
- Returns
name of the connection
- disconnectFromTerm() None
close the connection to Term and cleanup
Stops the thread used for receiving telegrams assynchronously and shuts down the network connection. Put None into the Queues to free the waiting threads. They wait in waitForBinaryTelegram and if they receive None from the Queue, the will throw an exception.
- isConnectedToTerm() bool
check if the connection to Term is open
- Returns
True if connected, False otherwise
- sendTelegram(payload: Union[str, bytearray], message_type: int, timeout: Optional[float] = None) None
send a telegram (data) to Term
Sending a telegram to the term. If the other thread hangs while sending and the semaphore cannot be aquired within the timout, then a TermConnectionError is thrown. If a timeout occurs in the socket, then an exception is thrown by the socket.
- Parameters
payload – The actual data which is being sent to Term. This can be a string or an bytearray.
message_type – Used internally by the DevCli dll. Depends on context. Most of the time 2.
timeout – The timeout for sending data in seconds, blocking at None.
- waitForBinaryTelegram(message_type: int = 2, timeout: Optional[float] = None) bytes
block infinitely until the next Telegram is arriving
If some Telegram has already arrived it will just return the last one from the queue.
- Parameters
message_type – Used internally by the DevCli dll. Depends on context. Most of the time 2.
timeout – The timeout for sending data in seconds, blocking at None
- Returns
The response from the device or an empty bytearray if someting went wrong.
- Return type
bytearray
- waitForStringTelegram(message_type: int = 2, timeout: Optional[float] = None) str
block infinitely until the next Telegram is arriving
If some Telegram has already arrived it will just return the last one from the queue.
- Parameters
message_type – Used internally by the DevCli dll. Depends on context. Most of the time 2.
timeout – The timeout for sending data in seconds, blocking at None
- Returns
The last received telegram or an empty string if someting went wrong.
- Return type
string
- sendStringAndWaitForReplyString(payload: Union[str, bytearray], message_type: int, timeout: Optional[float] = None, answer_message_type: int = None) str
convenience function: send a telegram and wait for it’s reply
If a timeout or a socket error occurs an exception is thrown.
- Parameters
payload – The actual data which is being sent to Term. This can be a string or an bytearray.
message_type – Used internally by the DevCli dll. Depends on context. Most of the time 2.
timeout – The timeout for sending data in seconds, blocking at None.
- Returns
The last received telegram or an empty string if someting went wrong.
- Return type
string
- _telegramListenerJob() None
runs in a separate thread, pushing the incomming packets into the queues.
- _startTelegramListener() None
starts the thread handling the asyncronously incoming data
- _stopTelegramListener() None
stops the thread handling the incoming data gracefully
- _readTelegramFromSocket() tuple[Optional[str], bytearray]
reads the raw telegram structure from the socket stream
When a socket exception occurs, None and an empty byte array are returned. The caller of the function then passes the None to the queue to raise an exception in the threads waiting at the queue.
- _closeSocket() None
close the socket