Module base class¶
The Module class serves as the base class for all Cockpit modules. Direct interaction with this base class is rare; interaction typically occurs through its derived specialized classes:
Retrieving an existing module¶
Existing modules can be retrieved directly from a project:
from imperix import Cockpit, ModuleType
with Cockpit() as cockpit:
# Look up the project by name
project = cockpit.projects.get("Central PV inverter")
if project is None:
raise SystemExit("Project not found.")
# Locate the Scope module
scope = None
for module in project.modules.list():
if module.type == ModuleType.SCOPE:
scope = module
break
if scope is None:
raise SystemExit("Scope module not found.")
# Interact with the Scope
scope.stop()
scope.set_window(window_ms=20.0)
scope.play()
scope.force_trigger()
Deleting and recreating a module¶
Existing modules can be deleted from a project and recreated with new configurations:
from imperix import Cockpit, ModuleType
with Cockpit() as cockpit:
# Retrieve a project by name
project = cockpit.projects["My project"]
# Iterate through modules and delete any existing Scope module
for module in project.modules.list():
if module.type == ModuleType.SCOPE:
print(f"Deleting {module.name}")
module.delete()
# Create and configure a new Scope module
scope = project.modules.create(ModuleType.SCOPE)
scope.add_variables(["Iout_ref", "Iout_meas"])
scope.set_window(window_ms=100.0)
The module types are defined by the ModuleType enumeration:
ModuleType.SCOPEModuleType.ROLLING_PLOTModuleType.XY_PLOTModuleType.SYS_ID
API Reference¶
- class imperix.Module(cockpit: Cockpit, data: dict[str, Any])¶
Base class for all module types.
- property id: int¶
Numeric module ID assigned by Cockpit.
- property project_id: int¶
ID of the project this module belongs to.
- property type: str¶
Module type string (e.g.
"scope").
- property name: str¶
Module name shown in Cockpit.
- delete(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) None¶
Delete this module from the project.
- Parameters:
timeout – Maximum time to wait for a response in seconds.
- class imperix.ModuleCollection(cockpit: Cockpit, *, project_id: int)¶
Modules from a project. Accessed via
modules.- list(*, timeout: float | None | UseDefaultTimeout = UseDefaultTimeout.TOKEN) list[Module]¶
Returns the list of the modules of a given project.
- Parameters:
timeout – Maximum time to wait for a response in seconds.
- Returns:
A list of
Moduleobjects. Known module types are returned asScopeModule,RollingPlotModule,XYPlotModule, orSysIdModule.
Example:
for module in project.modules.list(): print(module.id, module.name, module.type)
- create(module_type: Literal[ModuleType.SCOPE, 'scope'], *, timeout: TimeoutOption = USE_DEFAULT_TIMEOUT) ScopeModule¶
- create(module_type: Literal[ModuleType.ROLLING_PLOT, 'rolling_plot'], *, timeout: TimeoutOption = USE_DEFAULT_TIMEOUT) RollingPlotModule
- create(module_type: Literal[ModuleType.XY_PLOT, 'xy_plot'], *, timeout: TimeoutOption = USE_DEFAULT_TIMEOUT) XYPlotModule
- create(module_type: Literal[ModuleType.SYS_ID, 'sys_id'], *, timeout: TimeoutOption = USE_DEFAULT_TIMEOUT) SysIdModule
- create(module_type: ModuleType | str, *, timeout: TimeoutOption = USE_DEFAULT_TIMEOUT) Module
Creates a new module.
- Parameters:
module_type – The type of module to create (
SCOPE,ROLLING_PLOT, orXY_PLOT,SYS_ID).timeout – Maximum time to wait for a response in seconds.
- Returns:
A
ScopeModule,RollingPlotModule,XYPlotModule, orSysIdModuledepending on the module type.- Raises:
UnsupportedOperationError – If
module_typeis not supported.InvalidStateError – If the requested module cannot be created in the current project.
Example:
scope = project.modules.create(ModuleType.ROLLING_PLOT)
Enumerations