Client

class c104.Client

This class represents a local client and provides access to meta information and connected remote servers

__init__(self: c104.Client, tick_rate_ms: int = 100, command_timeout_ms: int = 10000, transport_security: c104.TransportSecurity = None) None

create a new 104er client

Parameters:
  • tick_rate_ms (int) – client thread update interval

  • command_timeout_ms (int) – time to wait for a command response

  • transport_security (c104.TransportSecurity, optional) – TLS configuration object

Example

>>> my_client = c104.Client(tick_rate_ms=100, command_timeout_ms=10000)
add_connection(self: c104.Client, ip: str, port: int = 2404, init=c104.Init.ALL) c104.Connection | None

add a new remote server connection to this client and return the new connection object

Parameters:
  • ip (str) – remote terminal units ip address

  • port (int) – remote terminal units port

  • init (c104.Init) – communication initiation commands

Returns:

connection object, if added, else None

Return type:

c104.Connection, optional

Raises:

ValueError – ip or port are invalid

Example

>>> con = my_client.add_connection(ip="192.168.50.3", port=2406, init=c104.Init.ALL)
disconnect_all(self: c104.Client) None

close all connections

Example

>>> my_client.disconnect_all()
get_connection(self: c104.Client, ip: str = '', port: int = 2404, common_address: int = 0) c104.Connection | None

get a connection (either by ip and port or by common_address)

Parameters:
  • ip (str, optional) – remote terminal units ip address

  • port (int, optional) – remote terminal units port

  • common_address (int, optional) – common address (value between 1 and 65534)

Returns:

connection object, if found else None

Return type:

c104.Connection, optional

Example

>>> conA = my_client.get_connection(ip="192.168.50.3")
>>> conB = my_client.get_connection(ip="192.168.50.3", port=2406)
>>> conC = my_client.get_connection(common_address=4711)
on_new_point(self: c104.Client, callable: collections.abc.Callable[[c104.Client, c104.Station, int, c104.Type], None]) None

set python callback that will be executed on incoming message from unknown point

Parameters:

callable (collections.abc.Callable[[c104.Client, c104.Station, int, c104.Type], None]) – callback function reference

Return type:

None

Raises:
  • ValueError – callable signature does not match exactly

  • **Callable signature**

  • Callable Parameters

  • -------------------

  • client – c104.Client: client instance

  • station – c104.Station: station reporting point

  • io_address – int: point information object address (value between 0 and 16777215)

  • point_type – c104.Type: point information type

  • Callable Returns

  • ----------------

  • None

Example

>>> def cl_on_new_point(client: c104.Client, station: c104.Station, io_address: int, point_type: c104.Type) -> None:
>>>     print("NEW POINT: {1} with IOA {0} | CLIENT OA {2}".format(io_address, point_type, client.originator_address))
>>>     point = station.add_point(io_address=io_address, type=point_type)
>>>
>>> my_client.on_new_point(callable=cl_on_new_point)
on_new_station(self: c104.Client, callable: collections.abc.Callable[[c104.Client, c104.Connection, int], None]) None

set python callback that will be executed on incoming message from unknown station

Parameters:

callable (collections.abc.Callable[[c104.Client, c104.Connection, int], None]) – callback function reference

Return type:

None

Raises:
  • ValueError – callable signature does not match exactly

  • **Callable signature**

  • Callable Parameters

  • --------------------

  • client – c104.Client: client instance

  • connection – c104.Connection: connection reporting station

  • common_address – int: station common address (value between 1 and 65534)

  • Callable Returns

  • -----------------

  • None

Example

>>> def cl_on_new_station(client: c104.Client, connection: c104.Connection, common_address: int) -> None:
>>>     print("NEW STATION {0} | CLIENT OA {1}".format(common_address, client.originator_address))
>>>     connection.add_station(common_address=common_address)
>>>
>>> my_client.on_new_station(callable=cl_on_new_station)
on_station_initialized(self: c104.Client, callable: collections.abc.Callable[[c104.Client, c104.Station, c104.Coi], None]) None

set python callback that will be executed on incoming end of initialization message from stations

Parameters:

callable (collections.abc.Callable[[c104.Client, c104.Station, c104.Coi], None]) – callback function reference

Return type:

None

Raises:
  • ValueError – callable signature does not match exactly

  • **Callable signature**

  • Callable Parameters

  • --------------------

  • client – c104.Client: client instance

  • station – c104.Station: reporting station

  • cause – c104.Coi: what caused the (re-)initialization procedure

  • Callable Returns

  • -----------------

  • None

Example

>>> def cl_on_station_initialized(client: c104.Client, station: c104.Station, cause: c104.Coi) -> None:
>>>     print("STATION {0} INITIALIZED due to {1} | CLIENT OA {2}".format(station.common_address, cause, client.originator_address))
>>>
>>> my_client.on_station_initialized(callable=cl_on_station_initialized)
reconnect_all(self: c104.Client) None

close and reopen all connections

Example

>>> my_client.reconnect_all()
start(self: c104.Client) None

start client and connect all connections

Example

>>> my_client.start()
stop(self: c104.Client) None

disconnect all connections and stop client

Example

>>> my_client.stop()
property active_connection_count

get number of active (open and not muted) connections to servers (read-only)

Type:

int

property connections

list of all remote terminal unit (server) Connection objects (read-only)

Type:

list[c104.Connection]

property has_active_connections

test if client has active (open and not muted) connections to servers (read-only)

Type:

bool

property has_connections

test if client has at least one remote server connection (read-only)

Type:

bool

property has_open_connections

test if client has open connections to servers (read-only)

Type:

bool

property is_running

test if client is running (read-only)

Type:

bool

property open_connection_count

represents the number of open connections to servers (read-only)

Type:

int

property originator_address

originator address of this client (0-255)

Type:

int

property tick_rate_ms

the clients tick rate in milliseconds (read-only)

Type:

int