You are on page 1of 5

Spectrum Power 7 v2.

30 SP2
PowerScript
1.1 Introduction
PowerScript

Application Sheet

1 PowerScript

1.1 Introduction
PowerScript is a tool that enables users to customize certain system behavior without modifying Spectrum
Power™ 7 directly. That is, users may write scripts calling standard APIs that impact certain AGC and SCADA
functionality without any source code modification. These scripts can be scheduled or called on-demand.

1.2 Highlights
The PowerScript framework has:

• A PowerScript Python API that provides extensions to the standard Python language which are made
available to interact with a Spectrum Power 7 system.

• The ability to connect Python objects to Analogs, Digitals and AGC TAs.

• Tagging capability support.

• Gather quality code information.

• Issuing Network Control for Analogs and Digitals commands.

• Support for synchronous and asynchronous methods.

• Alarm issuing capability.

• Full debugging capability.

• Script scheduling using a well-known syntax.

• Python template for the development of scripts.

• Logging capability

1.3 PowerScript Architecture


The PowerScript architecture consists of the PowerScript Scheduling Program (PSP) and PowerScript Hosting
programs (PSHosts).
As shown in the following figure (1), PSP is a program that is designated to run on COMs. It reads the Power-
Script scripts configuration files and manages their execution based on the configuration files.

Spectrum Power 7, PowerScript, Application Sheet 1 of 5


AS-PowerScript-EN, Edition 07.2021
PowerScript
1.3 PowerScript Architecture
The scripts are executed by PSHosts (Figure 1, (2)). These are single-threaded objects that communicates
with PSP using IPC messages. Each PSHost runs a single script inside a Python runtime environment and
informs PSP about the start and the end of the script execution.
Figure 1 (3) represents a list of scripts scheduled by the PSP. The script configuration file (Figure 1(4)) is an
INI file format that contains information about the script execution using a crontab like syntax. The configu-
ration file is read by the PSP that in turn schedule the script execution based on the configuration file.
The script execution represented by the Figure 1(5, 6, 7), depicts the usage of the PowerScript Framework
and the Python native APIs by the script.
Figure 1(8) shows a script execution though a WebUI.
In this case, the script execution will be trigged by the customer operator it doesn’t need a configuration file.

[dw_PowerScript execution workflow, 1, en_US]

Figure 1-1 PowerScript Execution Workflow

2 of 5 Spectrum Power 7, PowerScript, Application Sheet


AS-PowerScript-EN, Edition 07.2021
PowerScript
1.4 Script Development and Deployment

1.4 Script Development and Deployment


PowerScript scripts can be developed by any Integrated Development Environment (IDE) that supports
Python by using the PowerScript Python APIs. After the development and testing steps, the scripts are
deployed using the standard UPDASOS process. The following figure shows the whole development, testing,
and deployment workflow. This workflow should be followed in order to reduce the risks of scripts harming
the operation of the grid control system. Moreover, it is the customer responsibility to test and validate the
scripts. Siemens is not liable for any safety or security issues caused by scripts developed by the customer.

[dw_Script Development Workflow, 1, en_US]

Figure 1-2 PowerScript Development and Deployment Workflow

The script deployment for server-side execution requires a configuration file for each deployed script. Config-
uration files follow the Windows INI file format. In this format, each section is preceded by a keyword
wrapped inside a pair of square brackets “[ ]” followed by a list of key/value pairs.
All scripts have their own log files that are in /home/logs/powerscript/ folder. The naming convention is
scriptname.log, for example, if a script is called script1.py, its log file is called script1.log.
A configuration file example:
#This is the configuration file from the example.py script.
# It will be executed every 5 seconds
# SCRIPT_TIMEOUT means that if the script elapsed time is greater than 10 sec-
onds, the execution will be terminated.
# RUN_IN_BACKUP_SITE means whether the PSP will schedule the script on a
BACKUP SP7 Multisite configuration
# RUN_IN_STANDBY_COM means whether the PSP will schedule the script on a SP7
Distributed configuration
[example1.py]
# crontab sec[0-59] min[0-59] hrs[0-23] days[1-31] mon[1-12] dweek[0-6]
SCHEDULE= 0/5 * * * * *
SCRIPT_TIMEOUT = 10

Spectrum Power 7, PowerScript, Application Sheet 3 of 5


AS-PowerScript-EN, Edition 07.2021
PowerScript
1.5 PowerScript Python API
RUN_IN_BACKUP_SITE = false
RUN_IN_STANDBY_COM = false

1.5 PowerScript Python API


The PowerScript Python API provides PowerScript extensions to the standard Python language which are
made available to interact with a Spectrum Power 7 system.
An example of a PowerScript extension is AnalogPoint Class. This class is used to establish a reference
to a specific analog point in the SP7 system. The reference is established using a point string, for example a
TA4 (4-part Technological Address or Data Point), TA4Name, or TechId. If the point string provided does not
match a valid reference in the SP7 system, an exception is thrown back to the PowerScript script for error
handling.
Analog Example Usage:
# instantiating an Analog Object
analog: AnalogPoint = AnalogPoint(“ta4:/16/1/1/1”)

# printing out the analog quality code


print(analog.Quality)

# adding the “Remove From Operation” tag to the analog point


analog.AddTag(Tag.RemoveFromOp,"added removed from op")

# printing out the Analog value, its MvMoment(Manual Update).


print(analog.Value)

# printing out the timestamp


print(analog.Data.Timestamp)

# printing out analog information


analog.Describe()

# setting a value to the analog point, the MvMoment(Manual Update).


analog.Value = 17.2

# issuing control to the analog point, setting the MvMoment


ControlService.IssueControl(analog, 17.2, 5)

Digital Example Usage:


# instantiating a Digital Object
digital: StatusPoint = StatusPoint(“ta4name:/Sie/Par/Vie/Ps”)

# printing out the digital quality code


print(digital.Quality)

# printing out the digital state


print(digital.State)

# adding the “Remove From Operation” tag to the digital point


digital.AddTag(Tag.RemoveFromOp,"Removed from op")

# printing out the timestamp


print(digital.Data.Timestamp)
4 of 5 Spectrum Power 7, PowerScript, Application Sheet
AS-PowerScript-EN, Edition 07.2021
PowerScript
1.5 PowerScript Python API

# printing out digital information


digital.Describe()

# setting a new state to the digital point(Manual Update)


Digital.State = StatusStates.On

# issuing control to the digital point, setting its State


ControlService.IssueControl(digital, StatusStates.On, 5)
AGC Example Usage:
# instantiating an AGC Point
agcPoint: AGCPoint = AGCPoint(“techid:/56/12”)
# retrieving a digital info(connected) from the AGC object
connected: AGCData = agcPoint.Data(SrcUnitB.ScUConnect)
# setting to the connected info a new status(disconnected)
connected.Value = 0.0

# retrieving analog info(ScUP) from the AGC object


activePower: AGCData = agcPoint.Data(SrcUnitV.ScUP)
# setting a new info to the object
activePower.Value= activePower.Value + 5
For other PowerScript Python API references, refer to the PowerScript User Guide.

Spectrum Power 7, PowerScript, Application Sheet 5 of 5


AS-PowerScript-EN, Edition 07.2021

You might also like