Controller API#
RedSun uses controllers to manage the interaction between the user interface and the hardware.
Controllers can either render information (i.e. process some data and send it to the upper layer for visualization), notify of changes in the hardware state or publish Bluesky plans for the run engine to execute.
Each controller is associated with a ControllerInfo
object, which contains a series of user-defined properties that
describe the controller and provides further customization options.
Controllers can access specific hardware devices through the EngineHandler
, which holds
references to all the devices available in the application.
- class sunflare.controller.ControllerProtocol(*args, **kwargs)#
Controller protocol class.
- Parameters:
ctrl_info (
ControllerInfo
) – Controller information.handler (
EngineHandler
) – Engine handler.virtual_bus (
VirtualBus
) – Virtual bus.module_bus (
VirtualBus
) – Module bus.
- abstract connection_phase()#
Connect to other controllers or widgets.
At application start-up, controllers can’t know what signals are available from other parts of RedSun. This method is invoked after the controller’s construction and after registration_phase as well, allowing to connect to all available registered signals in both virtual buses. Controllers may be able to connect to other signals even after this phase (provided those signals were registered before).
An implementation example:
def connection_phase(self) -> None: # you can connect signals from another controller to your local slots... self._virtual_bus["OtherController"]["sigOtherControllerSignal"].connect( self._my_slot ) # ... or to other signals ... self._virtual_bus["OtherController"]["sigOtherControllerSignal"].connect( self.sigMySignal ) # ... or connect to widgets self._virtual_bus["OtherWidget"]["sigOtherWidgetSignal"].connect( self._my_slot ) # you can also connect to the module bus self._module_bus["OtherController"]["sigOtherControllerSignal"].connect( self._my_slot ) self._module_bus["OtherWidget"]["sigOtherWidgetSignal"].connect( self._my_slot )
- Return type:
None
- abstract property controller_info: ControllerInfo#
Controller class name.
- abstract property plans: list[partial[Generator[Msg, Any, Any]]]#
Set of available plans.
- abstract registration_phase()#
Register the controller signals listed in this method to expose them to the virtual buses.
At application start-up, controllers can’t know what signals are available from other controllers. This method is called after all controllers are initialized to allow them to register their signals. Controllers may be able to register further signals even after this phase (but not before the connection_phase ended).
Only signals defined in your controller can be registered.
An implementation example:
def registration_phase(self) -> None: # you can register all signals... self._module_bus.register_signals(self) # ... or only a selection of them self._module_bus.register_signals(self, only=["sigMySignal", "sigMyOtherSignal"]) # you can also register signals to the module bus self._module_bus.register_signals(self, only=["sigMySignal", "sigMyOtherSignal"])
- Return type:
None
- shutdown()#
Shutdown the controller. Performs cleanup operations.
If the controller holds any kind of resources, this method should invoke any equivalent shutdown method for each resource.
- Return type:
None