TelnetServerDevice

class dvg_devices.BaseDevice.TelnetServerDevice(name='Dev_1', long_name='Telnet Server Device')[source]

This class provides blocking I/O methods for a telnet server device by wrapping the telnetlib3 library.

The following functionality is offered:

Instances of this class will tie in nicely with dvg_qdeviceio.QDeviceIO.

Parameters:
  • long_name (str, optional) – Long display name of the device in a general sense. E.g., “Wemos ESP32-S3”.

    Default: “Telnet Server Device”

  • name (str, optional) – Short display name for the device. E.g., “ESP32” or “blinker”.

    Default: “Dev_1”

Example:

from dvg_devices.BaseDevice import TelnetServerDevice

dev = TelnetServerDevice()
dev.connect(host="10.10.100.2", port=23)
success, reply = dev.query("My query command")

Attributes:

long_name

Long display name of the device in a general sense. E.g, “Wemos ESP32-S3”.

Type:str
name

Short display name for the device. E.g., “ESP32” or “blinker”.

Type:str
telnet_settings

Dictionary of keyword arguments to be passed directly to telnetlib3.sync.TelnetConnection when calling method connect().

Default: {“timeout”: 4, “encoding”: “utf8”,}

Type:dict
conn

Will be set to a telnetlib3.sync.TelnetConnection instance when a connection has been established. Otherwise: None.

Type:telnetlib3.sync.TelnetConnection | None
is_alive

Is the connection alive? I.e., Can we communicate?

Type:bool

Methods

TelnetServerDevice.readline(raises_on_timeout: bool = False) Tuple[bool, Optional[Union[str, bytes]]][source]

Listen to the telnet server for incoming data. This method is blocking and returns when a full line has been received or when the read timeout has expired.

Parameters:

raises_on_timeout (bool, optional) – Should an exception be raised when a read timeout occurs?

Default: False

Returns:

success (bool):

True if successful, False otherwise.

reply (str | bytes, None):

Reply received from the device. None if unsuccessful.

Return type:

tuple

TelnetServerDevice.write(msg: str) bool[source]

Send a message to the telnet server.

Parameters:msg (str) – ASCII string to be sent to the serial device.
Returns:True if successful, False otherwise.
TelnetServerDevice.query(msg: str) Tuple[bool, Optional[Union[str, bytes]]][source]

Send a message to the telnet server and subsequently read the reply.

Parameters:msg (str) – ASCII string to be sent to the telnet server.
Returns:
success (bool):
True if successful, False otherwise.
reply (str | bytes | None):
Reply received from the device. None if unsuccessful.
Return type:tuple
TelnetServerDevice.close(ignore_exceptions=False)[source]

Close the telnet connection.