Cockpit¶
The Cockpit class serves as the main entry point for the imperix Python API, establishing a connection to a running Cockpit application.
Using the class as a context manager (via the with Cockpit() as cockpit: syntax) is highly recommended to ensure the connection is safely released after execution:
from imperix import Cockpit
with Cockpit() as cockpit:
targets = cockpit.targets.refresh()
# The rest of the script...
API Reference¶
- class imperix.Cockpit(*, default_timeout: float | None = 60.0, auto_start_cockpit: bool = True, cockpit_startup_timeout: float = 60.0)¶
Provides the interface to the Cockpit application.
- Parameters:
default_timeout – Maximum time to wait for Cockpit operations in seconds.
Nonedisables the timeout. Defaults to60.0.auto_start_cockpit – If Cockpit is not yet running, launches a new instance. Defaults to
True.cockpit_startup_timeout – Maximum time in seconds to wait for a connection to the Cockpit instance. Defaults to
60.0.
- projects¶
Returns the projects open in Cockpit
- targets¶
Returns the imperix controllers detected by Cockpit.
- Raises:
InvalidParamsError – If a timeout is not positive or
default_timeoutis notNoneor a positive number.
- connect() Self¶
Opens the connection to Cockpit application.
- Note: This method is called automatically when using the class as a context
manager (
with Cockpit() as cockpit:), which is the recommended approach. If the major API versions match but minor versions differ,VersionMismatchWarningis emitted once per connection. The connection stays open, but some features may be unavailable. Patch differences do not trigger a warning.
- Returns:
The
Cockpitinstance, allowing for method chaining- Raises:
BusyError – If another script is already connected to Cockpit.
CockpitConnectionError – If the connection fails.
VersionMismatchError – If the Python library and Cockpit have different major API versions.
Example:
cockpit = Cockpit() cockpit.connect() print(cockpit.system_version()) cockpit.close()
- close() None¶
Closes the connection to Cockpit.
Note: This method is called automatically when using the class as a context manager (
with Cockpit() as cockpit:), which is the recommended approach.- Raises:
CockpitConnectionError – If the underlying connection to Cockpit cannot be closed cleanly.
Example:
cockpit = Cockpit().connect() try: # Perform all operations that need the same scripting session. cockpit.targets.refresh() finally: cockpit.close()
- set_logging_level(level: int | str) None¶
Sets the logging verbosity level for the library.
- Parameters:
level – The desired logging level:
"INFO"or"DEBUG".- Raises:
InvalidParamsError – If
levelis not a recognized logging level.
Example:
cockpit.set_logging_level("INFO")
- disable_logging() None¶
Disable library logging.
Example:
cockpit.disable_logging()
- wait(*, delay_ms: float) None¶
Blocks execution for a fixed duration.
- Parameters:
delay_ms – Duration in milliseconds.
- Raises:
InvalidParamsError – If
delay_msis not a non-negative number.
Example:
scope.play() # Wait long enough for the scope pre-trigger rolling buffer to fill up. cockpit.wait(delay_ms=1500.0) project.variables["speed_ref"] = 1500.0
- wait_until(predicate: Callable[[], object], *, timeout: float | None = 60.0, interval: float = 1.0) None¶
Blocks execution until a condition becomes true.
Polls the provided
predicateeveryintervalseconds. This is useful for waiting on target or module state changes, such as a scope capture completing.- Parameters:
predicate – A callable evaluated repeatedly. The wait ends as soon as this returns a truthy value.
timeout – Maximum wait time in seconds.
Nonemeans wait forever. Defaults to60.0.interval – Time to wait between polls in seconds. Defaults to
1.0.
- Raises:
TimeoutError – If the
timeoutis reached before the predicate returns a truthy value.InvalidParamsError – If
timeoutis not positive orNone, or ifintervalis not a non-negative number.
Example:
scope.play() # Poll Cockpit until the armed scope has captured data. cockpit.wait_until(scope.is_capture_done, timeout=10.0) scope.export(r"C:\imperix\captures\scope_capture.mat")