Connection Methods#

The PSCAD Automation Library provides three methods of connecting to the PSCAD Application:

  1. Launching a new instance of PSCAD

  2. Connect to an existing PSCAD instance

  3. 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=None, allow_beta=False, load=None, extra_args=None, address=None, **options) PSCAD#

Launch a new PSCAD instance and return a connection to it.

Parameters:
  • port (int|range) – 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 (int) – 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)

  • load (list[str]) – Projects & libraries, or workspace to load at startup

  • extra_args (list[str]) – Additional command-line arguments

  • address (str) – Interface address to bind PSCAD’s automation server on

  • **options – Additional keyword=value options

Returns:

The PSCAD application proxy object

Return type:

PSCAD

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.

Changed in version 2.9.6: allow_alpha, allow_beta parameters are no longer supported.

Changed in version 3.0.2: added address parameter.

Changed in version 3.0.5: allow_beta parameter is supported again.

Existing Instance#

To connect to already running PSCAD instance, use the following command:

mhi.pscad.connect(host: str | None = None, port: int = 0, timeout: int = 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, or attempting to connect to a remote host.

  • timeout (int) – Seconds to wait for the connection to be accepted.

Returns:

The PSCAD application proxy object

Return type:

PSCAD

Example:

import mhi.pscad
pscad = mhi.pscad.connect()
pscad.load('myproject.pscx')

Added 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:

PSCAD

Example:

import mhi.pscad
pscad = mhi.pscad.application()
pscad.load('myproject.pscx')

Added in version 2.0.

Product Versions#

PSCAD#

mhi.pscad.versions() List[Tuple[str, bool]]#

Find the installed versions of PSCAD

Returns:

List of tuples of version and bit-size

Return type:

List[Tuple]

Fortran & Matlab#

Note

The Automation Library retrieves the list of installed Fortran and Matlab versions from the ProductsList.xml file. When any version of Fortran or Matlab is installed or uninstalled, run the Generate installed products list command from the Environment Medic utility in the PSCAD “Tools” menu.

mhi.pscad.fortran_versions() List[str]#

Find the installed versions of Fortran

Returns:

List of Fortran versions

Return type:

List[str]

mhi.pscad.matlab_versions() List[str]#

Find the installed versions of Matlab

Returns:

List of Matlab versions

Return type:

List[str]