Connection manager¶
-
class mundo.api.connection.ConnectionManager(
context: mundo.api.context.ApplicationContext,
simulate=False
)¶ Manages connecting and keeping the connection to controllers. Once connected, the X, Y, and Z axis controllers can be accessed via the
controllers
property.-
__init__(
context: mundo.api.context.ApplicationContext,
simulate=False
) None ¶ Initializes the connection manager and the underlying pyvisa resource manager.
- Parameters
context – The application context instance
simulate – If the connection should be simulated using the pyvisa-sim backend
- property controllers: Tuple[mundo.api.controller.BaseController, mundo.api.controller.BaseController, mundo.api.controller.BaseController]¶
Returns the connected X, Y, and Z controllers, if connected.
- Returns
A tuple of connected (X, Y, Z) controllers, or None if no controllers are connected
- property is_connected: bool¶
Checks if a connection has been successfully established with all three controllers.
- Returns
True if it is connected to the X, Y, and Z controllers. False otherwise
- available_controllers() Tuple[str, ...] ¶
Returns a list of plugged in controller device paths.
- Returns
A list of serial paths to plugged in controllers
-
connect_single(
controller: Type[mundo.api.controller.BaseController],
path: str
) Optional[mundo.api.controller.BaseController] ¶ Connects to a single controller at path. This method does not update the connection state of the connection manager, and thus you should manually call the
connect_using_controllers()
method once you have connected to all three X, Y, and Z controllers.The primary use-case of this method is to connect to a single controller during some sort of identification process.
- Parameters
controller – The controller class type
path – The path to the serial device
- Returns
An instantiated controller if successfull, or None if the connection failed
-
connect_using_config(
config: mundo.api.config.system.SystemConfig
) bool ¶ Attempts connection to X, Y, and Z controllers using the connection parameters stored in config. On success, the controllers will be available using the
controller
property.The name of the controllers will be automatically set to the axis it corresponds to, i.e. X, Y, or Z.
- Parameters
config – The system configuration to load connection parameters from
- Returns
True if the connection to X, Y, and Z controllers succeeded. False otherwise
-
connect_using_paths(
controller: Type[mundo.api.controller.BaseController],
paths: Tuple[str, str, str]
) bool ¶ Attempts connection to X, Y, and Z controllers using device paths. On success, the controllers will be available using the
controller
property.The name of the controllers will be automatically set to the axis it corresponds to, i.e. X, Y, or Z.
- Parameters
controller – The controller class type
paths – A tuple containing the X, Y, and Z controller device paths, respectively
- Returns
True if the connection to X, Y, and Z controllers succeeded. False otherwise
-
connect_using_controllers(
controllers: Tuple[mundo.api.controller.BaseController, mundo.api.controller.BaseController, mundo.api.controller.BaseController]
) bool ¶ Saves the connection to X, Y, and Z controllers using already connected controllers. This method should be used primarily if you have connected to devices during an identification process. On success, the controllers will be available using the
controller
property.This method should be used in conjuction with the
connect_single()
method.If possible, please use the
connect_using_config()
, orconnect_using_paths()
methods.The name of the controllers will be automatically set to the axis it corresponds to, i.e. X, Y, or Z.
- Parameters
controllers – A tuple containing the connected X, Y, and Z controllers
- Returns
True if the connection to X, Y, and Z controllers succeeded. False otherwise
-
identify_controller_at_path(
controller: Type[mundo.api.controller.BaseController],
path: str
) Optional[mundo.api.controller.BaseController] ¶ Attempts to connect to the controller at path, and tries moving it. This allows a user to see which motor is moving, thus identifying the axis of the controller.
This method only connects to the controller and runs the identification process. Ensuring that each axis is identified correctly should be done manually. Once each axis has been assigned to a controller, you can easily setup the connection using the
connect_using_controllers()
method.Once the identification process has been executed, the controller will be reset such that it is ready.
- Parameters
path – The path to the controller device
- Returns
The controller that has been connected to, or None, if the connection or identification process failed
- disconnect() None ¶
Disconnects from the connected controllers.
-
__init__(