Writing a Controller as an Executable Program
If the controller is written as an executable, it will use a shared file
for two-way communication with Bladed. When the simulation starts
up, the controller executable (.exe) file is first copied into the
directory where Bladed is installed, and renamed discon.exe
.
When discon.exe
starts up, the Bladed directory is the current
directory, and the files used to communicate between the simulation and
the controller are in this directory. The controller program can
therefore refer to these files by name without giving the full path.
Two files are used to communicate between the user-defined controller
program and the simulation. One of these is a text file named
discon.aux
, which is written by the simulation and just contains the
directory and run name for the simulation results. This may be useful if
the controller wishes to write any permanent record of what it does to
be stored with the simulation results. The file has just two lines: the
first consists of the word PATH
followed by a space and then the
path for the simulation results (including the final backslash). The
second line consists of the word RUNNAME
followed by a space and
then the run name (up to 8 characters). The controller may choose to
ignore this file if the information is not required.
The second file is used for the dynamic information exchange between the
two programs. It is called discon.swp
, and is a binary file with a
record length of 4 bytes. The file must be opened as a shared file, allowing simultaneous read and write access to both
programs. The file structure is defined in the Swap Array Interface Definition.
Although this file has many records, it may only be necessary for the controller to read from and write to a small number of these, depending on the turbine type and the tasks which the controller is performing.
Record 1 of discon.swp
is used for handshaking, to ensure that neither program starts reading data until the other program
has finished writing it. The sequence of events to be followed by the controller program is as follows:
Controller program starts by creating
discon.swp
and writing a zero to record 1.Controller program waits until record 1 becomes 1 or -1. If it is 1, this indicates that the simulation has finished writing data, and also that the file
discon.aux
is ready if required. If it is -1, the simulation is about to finish and the controller program should stop.If the first record is 1, the controller may read any of the parameters written by the simulation, perform its calculations, and then write the appropriate outputs. Once all data is written, the controller writes a zero to record 1 to tell the simulation that it is ready. If the controller decides to abort the simulation, it should write -1 to record 1, and write Messaging to
discon.swp
.Controller returns to step 2.
In step 2, the controller waits until record 1 becomes non-zero. It is
important that the controller closes and re-opens discon.swp
every
time around the loop, otherwise the contents of the file as represented
in the disc cache may not have been updated.
Last updated 29-08-2024