User Reference:Operator Module Scripting
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. Script execution is bound to a number of events that occur during various stages of BCI2000 system operation.
Events
- 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 quits. 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 executable. - SETCONFIG
Applies current parameters to the system. Corresponds to the SetConfig button. - 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 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. - 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 terminated commands, a line may contain multiple commands.
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
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
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.
--OnConnect "-LOAD PARAMETERFILE ..\parms\CursorTask_SignalGenerator.prm; SETCONFIG" --OnSetConfig "-SET STATE Running 1" --OnSuspend "-QUIT"