plesty.lib.traffic.tcp_ip

TCP/IP traffic manager for Plesty device communication.

Classes

TCPIPTrafficManager

A TrafficManager implementation for managing TCP/IP communication.

Module Contents

class plesty.lib.traffic.tcp_ip.TCPIPTrafficManager(host, port, timeout=5, write_termination='\r\n', read_termination='\r\n')

Bases: plesty.lib.traffic.TrafficManager

A TrafficManager implementation for managing TCP/IP communication.

This class provides methods to open, close, and communicate with instruments over TCP/IP.

Initialize with host, port, timeout, and termination characters.

host
port
write_termination = Multiline-String
Show Value
"""
"""
read_termination = Multiline-String
Show Value
"""
"""
_open(*args, **kwargs)

Open the TCP/IP connection to the instrument.

Parameters:
  • args – Positional arguments for the specific implementation (not used in this case).

  • kwargs – Keyword arguments for the specific implementation (not used in this case).

_close()

Close the connection to the resource.

Subclasses must implement this to handle the specific close logic.

receive_one(timeout: float | None = None) str | bool

We leave this function public for direct use in some cases where the caller needs more control over the receiving process (e.g. in some requests, two responses might be expected, one for instant feedback and one for the final report when the operation is complete).

Parameters:

timeout (float | None)

Return type:

str | bool

orphan(command: str) bool

Transmit command without receiving its answer.

Parameters:

command (str) – A command the peer will answer.

Returns:

True once transmitted, False when the socket is not open.

Return type:

bool

_send_command(command: str, timeout=None, expect_response=True)

Send a command to the resource and return the response.

Parameters:
  • command (str) – The command to send.

  • timeout – Timeout in seconds; defaults to the instance’s timeout.

  • *args – Additional positional arguments for subclass implementations.

  • **kwargs – Additional keyword arguments for subclass implementations.

Returns:

The response from the resource, or False if the command failed.

Return type:

Any