API Templates¶
In order to set you up quickly, there are two API templates, which allow to
create a Modbus client from a simple API definition. The API definition is
assumed to be provided in terms of a dictionary, which contains a meaningful
key (such as the numeric message ID or a string) as key and a
Payload object as value.
Default API Template¶
-
class
modbusclient.api_wrapper.ApiWrapper(api={}, host='', port=502, timeout=None, connect=False, unit=255)[source]¶ Default API implementation to quickly
Parameters: - api (dict) – Dictionary containing the API definition. Should contain
a string with desired method name as key and a
Payloadobject as value. - host (str) – IP address of the server. Passed verbatim to
Client - port (int) – Port to connect to at the server. Passed verbatim to
Client - timeout (int) – Client timeout. Passed verbatim to
Client - connect (bool) – Connect to the client. Defaults to False. Passed
verbatim to
Client
-
unit¶ int – Modbus unit ID: Defaults to NO_UNIT.
-
__exit__(type, value, traceback)[source]¶ Context Manager support
Logs out and disconnects from the server.
-
disconnect()[source]¶ Disconnect this client
If this client is connected, the socket will be shutdown and then closed. If the client is not connected, calling this method has no effect.
-
get(message)[source]¶ Get value of a single message
Parameters: message ( Payloador str) – Message to read from remote device. If this is not aPayloadinstance, the api dictionary will be used with message as key to lookup the payload.Returns: Value of message Return type: value
-
is_connected()[source]¶ Check if this client is connected to a server
Returns: True if and only if this client is connected to a server Return type: bool
-
is_logged_in()[source]¶ Check if this client is currently logged in
Intended to be implemented by derived class, if applicable
Returns: False. Return type: bool
-
load(settings)[source]¶ Load settings from dictionary
Parameters: settings (dict) – Dictionary with settings as returned by save()Returns: Successfully modified settings Return type: list
-
save(selection=None)[source]¶ Save current settings into dictionary
Parameters: selection (iterable) – Iterable of messages (API keys) to save. If None, all messages of the current API are backed up.Returns: Dictionary containing API message key and setting as value Return type: dict
- api (dict) – Dictionary containing the API definition. Should contain
a string with desired method name as key and a
Asynchronous API Template¶
-
class
modbusclient.asyncio.api_wrapper.ApiWrapper(api={}, host='', port=502, timeout=None, max_transactions=3, unit=255)[source]¶ Asynchronous API implementation
Parameters: - api (dict) – Dictionary containing the API definition. Should contain
a string with desired method name as key and a
Payloadobject as value. - host (str) – IP address of the server. Passed verbatim to
Client - port (int) – Port to connect to at the server. Passed verbatim to
Client - timeout (int) – Client timeout. Passed verbatim to
Client - max_transactions (int) – Maximum number of parallel transactions. Passed
verbatim to
Client. - unit (int) – Modbus unit ID to use. Defaults to NO_UNIT.
-
unit¶ int – Modbus unit ID: Defaults to NO_UNIT.
-
__aexit__(type, value, traceback)[source]¶ Context Manager support
Logs out and disconnects from the server.
-
disconnect()[source]¶ Disconnect this client
If this client is connected, the socket will be shutdown and then closed. If the client is not connected, calling this method has no effect.
-
get(message)[source]¶ Get value of a single message
Parameters: message ( Payloador str) – Message to read from remote device. If this is not aPayloadinstance, the api dictionary will be used with message as key to lookup the payload.Returns: Value of message Return type: value
-
is_connected()[source]¶ Check if this client is connected to a server
Returns: True if and only if this client is connected to a server Return type: bool
-
is_logged_in()[source]¶ Check if this client is currently logged in
Intended to be implemented by derived class, if applicable
Returns: False. Return type: bool
-
load(settings)[source]¶ Load settings from dictionary
Parameters: settings (dict) – Dictionary with settings as returned by save()Returns: Successfully modified settings Return type: list
-
save(selection=None)[source]¶ Save current settings into dictionary
Parameters: selection (iterable) – Iterable of messages (API keys) to save. If None, all messages of the current API are backed up.Returns: Dictionary containing API message key and setting as value Return type: dict
- api (dict) – Dictionary containing the API definition. Should contain
a string with desired method name as key and a