MED AS SOCI ATES I NC. SOF-735 ME D-PC
- 159 -
DOC-003 Rev 3.4 Copyright © 2012
MED Associates, Inc.
is not predictable, but there are methods that may be employed to determine whether a
BKGRND procedure has, in fact, executed; a technique for doing so is illustrated below.
BKGRND procedures are not called from MSN procedures via enclosure in tildes (~). Instead,
one issues the BKGRND output command accompanied by a number from 1 to 10. The numeric
parameter indicates which of up to 10 different user-written BKGRND procedures should be
called. As soon as the BKGRND command is executed, a request is made to MED-PC's internal
routines to process the BKGRND request as soon as some processing time is available. Under
normal circumstances the BKGRND procedure will be executed within a few tens or hundreds of
milliseconds, depending upon the processor on which MED-PC is executing, the number of
active Boxes, etc. If MED-PC is operating near capacity, in the sense that the average cycle time
(the "A" indicator on line one of the MED-PC runtime screen) approaches the resolution value
declared during installation, then it may take a second or two to begin execution of the
procedure.
Heavy disk activity could also slow the response time to BKGRND procedures. Due to the
indeterminacy of the delay until a BKGRND request is processed, it is important to issue requests
for BKGRND procedures only at times when it is possible to wait long enough for the request to
be honored and the procedure executed. Convenient times might include the beginning and
end of sessions, during long inter-trial intervals, time-outs between multiple schedule
components, etc.
The example below demonstrates how to call and write a BKGRND procedure. It shows how to
write a data file at the end of a session that contains information that will be read at the
beginning of the next session. This example could serve as the basis for developing MSN code
for "continuous" experimental sessions in which the events of one experimental session are
used to define the contingencies for a subsequent session. In S.S.1, S1, BKGRND procedure 2 is
requested and transition to S2 occurs. Note that transition from S2 will not occur until D equals
1. Examination of the Pascal code for BKGRND procedure 2 (below) shows that D is set to 1
after the data file is read. Thus, D indicates whether the BKGRND procedure has finished
execution. Of course, any variable could be used for this purpose, but D was chosen for the
present example. In the present example, the data file will have the same name as the Subject
running in the Box that called the BKGRND procedure plus a '.txt' extension and will be saved
in the default data folder.
(Example: MED-PC IV\DATA\animal 4500.txt).
The data file consists of the elements of array B. MED-PC automatically passes the Box number
to a BKGRND procedure when it is called, but note that no other parameters are passed to the
procedure. As a result, all parameters used by the procedure must be contained within MSN
arrays and variables. Using "D" as a flag to indicate completion of the BKGRND procedure and
reading data directly to and from "B" illustrates this aspect of utilizing BKGRND procedures.
Another mandatory aspect of employing BKGRND procedures is that the last line of the
procedure MUST be "BackRequest[Box][1] := False;", where the "1" is the number of the
BKGRND procedure; notice that both BKGRND procedures shown below include this line, except