Jump to content

User Reference:Operator Module Scripting

From BCI2000 Wiki
Revision as of 12:42, 12 August 2011 by Mellinger (talk | contribs)

Operator scripts automate actions that the otherwise would be performed by the user, e.g. starting or suspending system operation. Scripts may be contained in script files, or given immediately in the operator module's preferences dialog. There is also an option to specify scripts from the command line when starting the operator module. When using the Operator Library from your own application, you may execute scripts at any time.

Events

In the Operator GUI, script execution is bound to a number of events that occur during various stages of BCI2000 system operation:

OnConnect

This event is triggered at startup, as soon as all modules are connected to the operator module.

OnSetConfig

This event is triggered each time a set of parameters is applied to the system. This happens when the user clicks the SetConfig button. Execution of the SETCONFIG command also triggers this event.

OnStart, OnResume

These events correspond to the Start/Resume button. One of these events is also triggered when the Running state variable is set to 1 from a script. Whether OnStart or OnResume is triggered depends on whether the system has been running before with the current set of parameters.

OnSuspend

Triggered when the system goes from running into suspended mode. This happens whenever the Running state variable changes from 1 to 0. This may happen when the user clicks Suspend, when the application module switches the system into suspended mode, or when a script sets the Running state variable to 0.

OnExit

Triggered when the operator module exits. Execution of the QUIT command also triggers this event.

Commands

LOAD PARAMETERFILE <file>

Loads a parameter file specified by its path and name. Relative paths are interpreted relative to the operator module's working directory at startup. Usually, this matches the executable's location in the prog directory. As the parameter file name must not contain white space, please use HTML-type encoding for white space characters, such as Documents%20and%20Settings when referring to a user's "Documents and Settings" folder.

INSERT STATE <name> <bit width> <initial value>

Adds a state variable to the system. State variables are defined by name, bit width, and initial value (see Technical Reference:State Definition). This command may not be used after system initialization has completed, i.e. its use is restricted to the "Idle" and "Publishing" phases of system operation. In terms of events, its use is restricted to the OnConnect event.

INSERT PARAMETER <parameter definition>

Adds a parameter to the system. The parameter is specified as a parameter line. This command may not be used after system initialization has completed, i.e. its use is restricted to the "Idle" and "Publishing" phases of system operation. In terms of events, its use is restricted to the OnConnect event.

SET STATE <name> <value>

Sets the named state variable to the specified integer value. Setting the Running state to 1 will start system operation, setting it to 0 will suspend the system.

SET PARAMETER <name> <value>

Sets the named parameter to the specified value. Values that contain special characters, or whitespace must use the parameter value encoding.

SET VISPROPERTY <visID>.<name> <value>

Sets the named visualization property for the specified visualization ID to the given value. If the visualization ID contains a dot character, it must be encoded in parameter value encoding. E.g., setting the window width for the visualization ID "2.D1" would be written SET VISPROPERTY 2%2ED1.Width 200.

SET VISPROPERTIES <property set ID>

Applies a set of visualization property values as given in the VisPropertySets parameter. In that matrix-valued parameter, row labels specify visualization properties such as "SRCD.Left", and columns represent sets of property values. Column labels are IDs of the corresponding property sets.

SETCONFIG

Applies current parameters to the system. Corresponds to the SetConfig button in the GUI version of the Operator module.

START

Starts or resumes system operation, corresponding to the Start/Resume button in the GUI version of the Operator module.

STOP

Stops system operation. Corresponds to the Stop button in the GUI version of the Operator.

QUIT

Quits the operator module after terminating all BCI2000 modules.

SYSTEM <command line>

Executes a single-line shell command.

Syntax

Scripts consist of sequences of the above commands, terminated with either a DOS line ending sequence, or a semicolon (;). When the semicolon is used to terminate commands, a line may contain multiple commands. Commands are case-insensitive, values are case-sensitive.

Specifying Scripts

In the operator module's preferences dialog, scripts may be entered for each of the events listed above. Scripts may be specified as paths to script files, or as immediate one-line scripts. Entries that start with a minus sign (-) are treated as one-line scripts, which may contain multiple commands separated with semicolons.

Scripts may also be specified from the command line used to start up the operator module. There, event names are followed with the content of the respective preference entry, enclosed in double quotes ("...").

Examples

1

To add a state variable called "Artifact", and to set it using the operator's function buttons, do this:

  • Enter the following line under "After All Modules Connected" in the operator's preferences dialog (note the minus sign):
-INSERT STATE Artifact 1 0
  • Under "Function Buttons", enter "Set Artifact" as the name of button 1, and as its command, enter (note there is no minus sign):
SET STATE Artifact 1
  • Enter "Clear Artifact" as the name of button 2, and as its command, enter
SET STATE Artifact 0

2

The following example shows how to specify script commands from the command line. It fully automates BCI2000 operation by loading a parameter file, applying parameters, starting the system once the parameters are applied, and quitting the system once the run is over. For better readability, the example is broken across lines; for execution, the command needs to be entered as a single line.

operat.exe --OnConnect "-LOAD PARAMETERFILE ..\parms\examples\CursorTask_SignalGenerator.prm; SETCONFIG" 
           --OnSetConfig "-SET STATE Running 1"  
           --OnSuspend "-QUIT"

See also

User Reference:Module Command Line Options, User Reference:Operator Module, Technical Reference:States of Operation