Version 2.0.0-b1
UnityBCI2000 has been rewritten to use the new version of the BCI2000RemoteNET library. This will bring more reliable communication and control of BCI2000.
Interface changes are extensive, and migration to version 2.0 is non-trivial, but recommended for reliability and ease of maintenance.
The major interface changes are as follows:
-
Starting a local operator is now explicit through the
StartLocalOperator
option, which will start the operator whose executable is located atOperatorPath
listening for input atOperatorAddress:OperatorPort
. -
Control of BCI2000 is done directly through BCI2000RemoteNET, unifying the interface and removing the shim layer of
UnityBCI2000
methods. This is done by going through theControl
member property ofUnityBCI2000
, for example, in order to set an event:
UnityBCI2000 bci = ...; bci.Control.SetEvent("event", 1);
BCI2000RemoteNET is found here: https://github.com/neurotechcenter/BCI2000RemoteNET
Full documentation will be hosted on bci2000.org soon, but the source code is fully documented and html documentation can be generated using doxygen.
The Control
property cannot be accessed during scene initialization (Awake, Start) during scene initialization due to how the order of initialization of game objects being undefined. UnityBCI2000
instead provides methods OnIdle()
and OnConnected()
which take Action<BCI2000Remote>
delegates and run them with the BCI2000Remote
instance during Start()
, before and after BCI2000's modules are started, respectively. This is to provide a way to ensure that certain operations such as adding events or setting parameters occur when BCI2000 is in a valid state to do so, as, for example, events and parameters cannot be added once the BCI2000 modules have started.
Adding a parameter to BCI2000:
void Awake() { UnityBCI2000 bci = ...; bci.OnIdle( bci => { bci.AddParameter("Application:AParam", "AParam", "1"); }); }
Adding and visualizing events:
void Awake() { UnityBCI2000 bci = ...; bci.OnIdle( bci => { bci.AddEvent("EventX", 32, 0); bci.AddEvent("EventY", 16, 0); }); bci.OnConnected( bci => { bci.Visualize("EventX"); bci.Visualize("EventY"); }); }
Keep in mind that these only have a defined order if BCI2000's startup is not being controlled manually, that is, if options such as StartModules
, StartWithScene
, etc. are left as default. Otherwise they simply run the commands during the Start()
method. For example, if BCI2000 is already running and you are simply connecting to it, trying to use BCI2000Remote.AddEvent()
will fail no matter what.
Note on BCI2000RemoteNET:
UnityBCI2000 uses the .NET Standard version of BCI2000RemoteNET, maintained on the netstandard2.1
branch. If you are compiling BCI2000RemoteNET yourself, make sure you compile from that branch. This will hopefully cease to be a problem when Unity implements support for .NET 8.0.