PGM Introduction

From SysCAD Documentation
Jump to: navigation, search

Navigation: PGMs


SysCAD uses the PGM (Programmable Module) language in a number of contexts, mainly in the General Controller Model and Model Procedures. A subset of the PGM commands can be used in the PID Controller Model and in SysCAD Trend pages.

The PGM language offers the following facilities:

  • Accessing permissible variables by name within any unit or stream on the flowsheet.
  • Modification of any permissible variables within any unit or stream.
  • Real, integer, Boolean and Bitwise arithmetic.
  • Strings and string manipulation routines.
  • Displaying of PGM local variables at run time and allowing charting of these variables.
  • Can make use of a number of supplied PGM classes, (see Predefined Classes).
  • Custom general-purpose functions and classes may be coded.

PGM code is executed once per SysCAD iteration. It allows the user to develop sophisticated programs to control the SysCAD model and to emulate real plant conditions.

Text Editor

The PGM file is a text file in a pre-defined format. It must be created using a text editor or word processor. If a word processor is used, the user must ensure that the file is converted into a text file free of control characters other than the carriage return, tab and line feed characters.

We recommend that you use Notepad++ as the text editor for control files. (Please see Using Notepad++ for more information on installing and setting up this software)

Other editors that SysCAD users have found convenient are Textpad, UltraEdit and Emacs, the links give some notes on setup.

How to create and use PGM file in SysCAD

To Create a new PGM file in a General Controller for use in a project, do the following:

  1. In a project, insert a General Controller.
  2. On the access window of the General controller, press the Edit_PGM button. SysCAD will create a text file with the same name as the General Controller unit.
  3. Alternatively, the user may type in the required name of the pgm file in the PGM_Name field. Please note that the file MUST ahve the extension .pgm.

To use an existing PGM file in a General Controller, do the following:

  1. In a project, insert a General Controller.
  2. On the access window of the General controller, press the Browse_PGM button.
  3. The user may then browse to the required .pgm file and click on the 'Open' button.

A similar procedure is used for Model Procedures.

Example -- Blank file auto generated by SysCAD

SysCAD 9.3 Format SysCAD 9.2 Format
;--- SysCAD General Controller (PGM) program logic file ---
; Revision: 1     Date:     Author:

;--- variable declarations ---

;--- Logic - executed at EVERY step --- 

$ ; --- end of file ---
; Following lines are ALL IGNORED - SysCAD does not recognise anything after the $ symbol.

; Useful quick reference for optional procedures executed before first step or after last step.

Sub InitialisePreStart()
  ;--- Logic executed very early before first iteration,
  ;For example to activate/deactivate flowsheets or turn controllers/units on/off

Sub PreStart()
  ;--- Logic executed early before first iteration,
  ;For example to turn controllers/units on or off, set options/methods

Sub InitialiseSolution()
  ;--- Logic executed during initialisation before first iteration
  ;For example to set initial values, or set values in units

Sub TerminateSolution()
  ;--- Logic executed after last iteration (when solver is stopped)
  ;For example calculate values for reporting
;--- SysCAD General Controller (PGM) program logic file ---
;--- variable declarations --- 
if (OnInitialise)
  ;--- place logic here for execution before first iteration --- (use SetDynTag in OnInitialise)
  ;--- place logic here for normal execution each iteration ---
; --- end of file ---

Template file

There is the flexibility to allow a template pgm file to be used. This template must be called template.pgm and can be placed in either the CfgFiles folder used by the project or the BaseFiles folder of the SysCAD installation. A full installation of SysCAD will include a file called template.pgm in the BaseFiles folder. The user may edit this file to suit. SysCAD will look in the CfgFiles folder first for a template and then the BaseFiles folder if one is not found in the CfgFiles folder.

The same is true for include files. In this case, the template is called