Connection Methods¶
The PSCAD Automation Library provides three methods of connecting to the PSCAD Application:
Launching a new instance of PSCAD
Connect to an existing PSCAD instance
Connect to an existing PSCAD instance if any, or launch a new instance of PSCAD otherwise.
New Instance¶
To launch and connect to new PSCAD instance, use the following command:
- mhi.pscad.launch(port=None, silence=True, minimize=False, splash=False, timeout=5, version=None, x64=None, settings=None, load_user_profile=None, minimum='5.0', maximum=None, allow_alpha=False, allow_beta=False, load=None, extra_args=None, **options) PSCAD ¶
Launch a new PSCAD instance and return a connection to it.
- Parameters:
port (int) – The port to connect to. Required if running multiple PSCAD instances.
silence (bool) – Suppresses dialogs which can block automation.
minimize (bool) – True to minimize PSCAD to an icon.
splash (bool) – False to disable the startup splash/logo window.
timeout (float) – Time (seconds) to wait for the connection to be accepted.
version (str) – Specific version to launch if multiple versions present.
x64 (bool) – True for 64-bit version, False for 32-bit version.
settings (dict) – Setting values to set immediately upon startup.
load_user_profile (bool) – Set to False to disable loading user profile.
minimum (str) – Minimum allowed PSCAD version to run (default ‘5.0’)
maximum (str) – Maximum allowed PSCAD version to run (default: unlimited)
allow_alpha (bool) – Allow launching an “alpha” version of PSCAD.
allow_beta (bool) – Allow launching a “beta” version of PSCAD.
load (list[str]) – Projects & libraries, or workspace to load at startup
extra_args (list[str]) – Additional command-line arguments
**options – Additional keyword=value options
- Returns:
The PSCAD application proxy object
- Return type:
Example:
import mhi.pscad pscad = mhi.pscad.launch(load='myproject.pscx')
Changed in version 2.4: added extra_args parameter.
Changed in version 2.8.4: added load parameter.
Existing Instance¶
To connect to already running PSCAD instance, use the following command:
- mhi.pscad.connect(host: str = 'localhost', port: int = None, timeout: float = 5) PSCAD ¶
This method will find try to find a currently running PSCAD application, and connect to it.
- Parameters:
host (str) – The host the PSCAD application is running on (defaults to the local host)
port (int) – The port to connect to. Required if running multiple PSCAD instances.
timeout (float) – Seconds to wait for the connection to be accepted.
- Returns:
The PSCAD application proxy object
- Return type:
Example:
import mhi.pscad pscad = mhi.pscad.connect() pscad.load('myproject.pscx')
New in version 2.0.
If multiple instances are running, the Automation Library will connect
to one of them.
If the port which the desired instance of PSCAD is listening on is known,
the port=#
option may be given in connect()
:
pscad = mhi.pscad.connect(port=54321)
If the desired PSCAD instance is running on another machine,
the host="..."
parameter must be given as well:
pscad = mhi.pscad.connect(host="192.168.0.123", port=54321)
Existing or New¶
To connect to any running PSCAD instance, or launch & connect to a new PSCAD instance if there are no existing instances, or if running the script from inside PSCAD itself, use the following command:
- mhi.pscad.application() PSCAD ¶
This method will find try to find a currently running PSCAD application, and connect to it. If no running PSCAD application can be found, or if it is unable to connect to that application, a new PSCAD application will be launched and a connection will be made to it.
If running inside a Python environment embedded within an PSCAD application, the containing application instance is always returned.
- Returns:
The PSCAD application proxy object
- Return type:
Example:
import mhi.pscad pscad = mhi.pscad.application() pscad.load('myproject.pscx')
New in version 2.0.