Guides

Calling a connector action

Executing a simple action.

Pre-requisite: Follow the steps described in the previous tutorial (Importing a connector) and import the thermocycler connector.

Understanding actions

Actions are all the methods within a module that are implemented by the connector interface. SiLA 2 or OPC UA specific endpoints are all mapped to 'actions'. Thus, the term action refers to these in an abstract way. The specific types of endpoints are then mapped to "Controls", "Sensors", and "Properties", defining how they can be interacted with.

Getting all available actions

Instantiate a thermocycler object and check which modules are implemented using thermocycler.modules.keys(). You can then get the available actions of a module by checking the actions property.

print(thermocycler.temperature_controller.actions.keys())

The result for the thermocycler example server should look like this:

dict_keys(['get_target_temperature', 'subscribe_current_temperature', 'set_target_temperature'])

To determine the type of an action, append .type after the action.

For example

print(thermocycler.temperature_controller.get_target_temperature.type)

will result in

PROPERTY

Parameters and responses of an action

The parameters and responses are displayed in the connector browser, but they are also attributes of that action. Use the parameters and responses attribute to see what the method is expecting and returning.

For example the set_targe_temperature action expects a 'target_temperature' in °C and returns nothing.

print(await thermocycler.temperature_controller.set_target_temperature.parameters)

Resulting in:

{'target_temperature': Parameter(id='TargetTemperature', schema={'dataType': {'name': 'Constrained', 'dataType': {'name': 'Integer'}, 'constraints': [{'name': 'Unit', 'label': '°C', 'factor': 1, 'offset': 273, 'components': [{'unit': 'Kelvin', 'exponent': 1}]}]}, 'identifier': 'TargetTemperature', 'description': 'The new target temperature in °C to reach and hold.', 'displayName': 'Target Temperature'})}
print(await thermocycler.temperature_controller.set_target_temperature.responses)
{}

The get_target_temperature action on the other hand, expects nothing, but returns a 'target_temperature' integer in °C.

print(await thermocycler.temperature_controller.get_target_temperature.responses)
print(await thermocycler.temperature_controller.get_target_temperature.responses)
{'TargetTemperature': Response(name='target_temperature', schema={'dataType': {'name': 'Constrained', 'dataType': {'name': 'Integer'}, 'constraints': [{'name': 'Unit', 'label': '°C', 'factor': 1, 'offset': 273, 'components': [{'unit': 'Kelvin', 'exponent': 1}]}]}, 'identifier': 'TargetTemperature', 'description': 'Returns the currently set target temperature in °C.', 'displayName': 'Target Temperature'})}

Using an action

Set the temperature setpoint to 20 °C with:

await thermocycler.temperature_controller.set_target_temperature(target_temperature=20)

You can now check if the setting of the target temperature was successful with:

await thermocycler.temperature_controller.get_target_temperature()

Copyright © 2024