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 = 1000, command_timeout_ms: int = 1000, transport_security: c104.TransportSecurity | None = 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 (TransportSecurity) – TLS configuration object
Example
>>> my_client = c104.Client(tick_rate_ms=1000, command_timeout_ms=1000)
- 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:
- Returns:
connection object, if added, else None
- Return type:
- Raises:
ValueError – If 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) c104.Connection | None
get a connection by ip and port
- Parameters:
- Returns:
connection object, if found else None
- Return type:
Example
>>> con = my_client.get_connection(ip="192.168.50.3", port=2406)
get_connection(self: c104.Client, common_address: int) -> Optional[c104.Connection]
get a connection by common_address
- Parameters:
common_address (int) – common address (value between 0-65535)
- Returns:
connection object, if found else None
- Return type:
Example
>>> con = my_client.get_connection(common_address=4711)
- on_new_point(self: c104.Client, callable: Callable[[c104.Client, c104.Station, int, c104.Type], None]) None
set python callback that will be executed on incoming message from unknown point
Callable signature
- Parameters:
- Return type:
None
- Raises:
ValueError – If callable signature does not match exactly
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: Callable[[c104.Client, c104.Connection, int], None]) None
set python callback that will be executed on incoming message from unknown station
Callable signature
- Parameters:
client (Client) – client instance
connection (Connection) – connection reporting station
common_address (int) – station common address (value between 0-65535)
- Return type:
None
- Raises:
ValueError – If callable signature does not match exactly
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)
- 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 connections
list of all remote terminal unit (server) Connection objects (read-only)
- Type:
List[Connection]
- property has_connections
test if client has at least one remote server connection (read-only)
- Type: