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 = 100, transport_security: Optional[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 (Optional[c104.TransportSecurity]) – TLS configuration object
Example
>>> my_client = c104.Client(tick_rate_ms=100, command_timeout_ms=100)
- add_connection(self: c104.Client, ip: str, port: int = 2404, init=c104.Init.ALL) Optional[c104.Connection]
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) Optional[c104.Connection]
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) -> typing.Optional[c104.Connection]
get a connection by common_address
- Parameters:
common_address (int) – common address (value between 1 and 65534)
- 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: 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
Callable signature
- 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
- 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: collections.abc.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 (c104.Client) – client instance
connection (c104.Connection) – connection reporting station
common_address (int) – station common address (value between 1 and 65534)
- 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 active_connection_count
get number of active (open and not muted) connections to servers (read-only)
- Type:
- property connections
list of all remote terminal unit (server) Connection objects (read-only)
- Type:
- property has_active_connections
test if client has active (open and not muted) connections to servers (read-only)
- Type:
- property has_connections
test if client has at least one remote server connection (read-only)
- Type:
- property has_open_connections
test if client has open connections to servers (read-only)
- Type: