Jump to content

User Tutorial:BCI2000Remote: Difference between revisions

From BCI2000 Wiki
Nluczak (talk | contribs)
No edit summary
Nluczak (talk | contribs)
No edit summary
Line 5: Line 5:
==Note==
==Note==
BCI2000Remote is a means of interfacing with the BCI2000 Operator module meaning that there are potentially hundreds of ways we leverage this tool to have a meaningful interface with BCI2000. Because of this we will illustrate a few different integrations using different languages. This "How-to" will be separated into three separate sections: Python, C++, and Matlab.
BCI2000Remote is a means of interfacing with the BCI2000 Operator module meaning that there are potentially hundreds of ways we leverage this tool to have a meaningful interface with BCI2000. Because of this we will illustrate a few different integrations using different languages. This "How-to" will be separated into three separate sections: Python, C++, and Matlab.
==Tutorial==
==Python Tutorial==
<ol>
<ol>
<li>Download the PsychoPy standalone version from the PsychoPy [https://www.psychopy.org/download.html downloads page].<br/>
<li>Find your Python folder. If you have an existing Python environment with your code find it using the Sys Library like this:  
<tt>import sys</tt>


 
<tt>locate_python = sys.exec_prefix</tt>
[[File:Psychopy1.png]]
<tt>print(locate_python)</tt>
</li>
<li>Copy the folders '''BCIStart''' and '''BCIUpdateState''' from the ''src/contrib/PsychoPy Components'' directory of your BCI2000 repository into the folder {$PsychoPyHome}\Lib\site-packages\psychopy\experiment\components
 
 
[[File:Psychopy2.png]]
</li>
</li>
<li>
<li>
Open PsychoPy and then open your experiment file (StroopExtended is what we use in the demo)
Locate your BCI2000Remote.py file which should have compiled into your prog folder.  
 
 
[[File:Psychopy3.png]]
</li>
</li>
<li>
<li>
Open the part of the experiment where you want to start BCI2000 (in this case the ''instruct'' tab) and look under the custom section of the components for the '''BCI Connect''' and '''BCI Update State''' components
Find where in your Python code you wish to integrate BCI2000. In this example I will show the minimum requirements for integration with BCI2000:
 
<tt>
 
import sys
[[File:Psychopy4.png]]
sys.path.append('C:\\BCI2000\\prog')
import BCI2000Remote
bci = BCI2000Remote.BCI2000Remote()
//print('Operator path:', bci.OperatorPath)
bci.WindowVisible = True
bci.WindowTitle = 'Python controlled'
bci.SubjectID = 'pysub'
bci.Connect()
bci.Execute('cd ${BCI2000LAUNCHDIR}')
bci.Execute('ADD STATE score 16 0')
bci.StartupModules(('SignalGenerator', 'DummySignalprocessing', 'DummyApplication'))
bci.Execute('Wait for Connected')
bci.SetConfig()
</tt>
Here is how you import BCI2000Remote:
[[File:BCIRemote.jpg]]
Here is how you instantiate the operator object:
[[File:BCIRemote_2.jpg]]
Here is how to customize the operator and connect to it:
[[File:BCIRemote_3.jpg]]
Here is how you add your states:
[[File:BCIRemote_4.jpg]]
How to specify your signal source, signal processing, and application modules:
[[File:BCIRemote_5.jpg]]
How to connect and issue commands to BCI2000:
[[File:BCIRemote_6.jpg]]
And finally, how to tell BCI2000 to set states to a value during runtime:
[[File:BCIRemote_6.jpg]]
</li>
</li>
<li>
<li>
Add the BCI2000 Start Component by clicking on it.  
Now that you've added those components to your code all you have to do is run your code. You should see the BCI2000 operator along with the system log, source watcher, and the timing window.
[[File:BCIRemote_7.jpg]]
</li>
</li>
<li>
</ol>
Enter the path to the prog folder in the BCI2000 directory where your BCI2000Remote.py file exists
==C++ Tutorial==
 
<ol>
<li>Find your Python folder. If you have an existing Python environment with your code find it using the Sys Library like this:
<tt>import sys</tt>


[[File:Psychopy5.png]]
<tt>locate_python = sys.exec_prefix</tt>
<tt>print(locate_python)</tt>
</li>
</li>
<li>
<li>
Add the states that you want to record separated by commas (the first value will always be the default value and the second value will always be the maximum value)
Locate your BCI2000Remote.py file which should have compiled into your prog folder.  
 
 
[[File:Psychopy6.png]]
</li>
</li>
<li>
<li>
Add the BCIUpdateState component to where you want to update state values. You can either choose to simply pass a variable through BCIUpdateState, or you can specify that it execute a specific Python script by choosing the "Use Expression" ticker
Find where in your Python code you wish to integrate BCI2000. In this example I will show the minimum requirements for integration with BCI2000:
 
<tt>
 
import sys
[[File:Psychopy7.png]]
sys.path.append('C:\\BCI2000\\prog')
 
import BCI2000Remote
 
bci = BCI2000Remote.BCI2000Remote()
[[File:Psychopy8.png]]
//print('Operator path:', bci.OperatorPath)
bci.WindowVisible = True
bci.WindowTitle = 'Python controlled'
bci.SubjectID = 'pysub'
bci.Connect()
bci.Execute('cd ${BCI2000LAUNCHDIR}')
bci.Execute('ADD STATE score 16 0')
bci.StartupModules(('SignalGenerator', 'DummySignalprocessing', 'DummyApplication'))
bci.Execute('Wait for Connected')
bci.SetConfig()
</tt>
Here is how you import BCI2000Remote:
[[File:BCIRemote.jpg]]
Here is how you instantiate the operator object:
[[File:BCIRemote_2.jpg]]
Here is how to customize the operator and connect to it:
[[File:BCIRemote_3.jpg]]
Here is how you add your states:
[[File:BCIRemote_4.jpg]]
How to specify your signal source, signal processing, and application modules:
[[File:BCIRemote_5.jpg]]
How to connect and issue commands to BCI2000:
[[File:BCIRemote_6.jpg]]
And finally, how to tell BCI2000 to set states to a value during runtime:
[[File:BCIRemote_6.jpg]]
</li>
</li>
<li>
<li>
Run the experiment
Now that you've added those components to your code all you have to do is run your code. You should see the BCI2000 operator along with the system log, source watcher, and the timing window.
 
[[File:BCIRemote_7.jpg]]
 
[[File:Psychopy9.png]]
 
 
[[File:Psychopy10.png]]
</li>
</li>
</ol>
==Video==
==Video==
<youtube alignment="center">https://www.youtube.com/watch?v=yPacLewE3Xo&list=PL6LrR5Nj3cAxOxKHNsnqyKfLDGikpi8Qi&index=4</youtube>
<youtube alignment="center">https://www.youtube.com/watch?v=yPacLewE3Xo&list=PL6LrR5Nj3cAxOxKHNsnqyKfLDGikpi8Qi&index=4</youtube>

Revision as of 01:05, 11 October 2021

Description

BCI2000Remote is a proxy interface class to the BCI2000 Operator module, and allows to start up, configure, and control BCI2000 from other applications. Internally, it maintains a telnet connection to the Operator module, and sends Operator Scripting commands to control it. However, no knowledge of these scripting commands is required in order to use the BCI2000Remote class from your own application.

BCI2000Remote is most useful when writing applications in C++, or in another language for which bindings to the BCI2000RemoteLib library exist, such as Python, or MATLAB.

Note

BCI2000Remote is a means of interfacing with the BCI2000 Operator module meaning that there are potentially hundreds of ways we leverage this tool to have a meaningful interface with BCI2000. Because of this we will illustrate a few different integrations using different languages. This "How-to" will be separated into three separate sections: Python, C++, and Matlab.

Python Tutorial

  1. Find your Python folder. If you have an existing Python environment with your code find it using the Sys Library like this: import sys locate_python = sys.exec_prefix print(locate_python)
  2. Locate your BCI2000Remote.py file which should have compiled into your prog folder.
  3. Find where in your Python code you wish to integrate BCI2000. In this example I will show the minimum requirements for integration with BCI2000: import sys sys.path.append('C:\\BCI2000\\prog') import BCI2000Remote bci = BCI2000Remote.BCI2000Remote() //print('Operator path:', bci.OperatorPath) bci.WindowVisible = True bci.WindowTitle = 'Python controlled' bci.SubjectID = 'pysub' bci.Connect() bci.Execute('cd ${BCI2000LAUNCHDIR}') bci.Execute('ADD STATE score 16 0') bci.StartupModules(('SignalGenerator', 'DummySignalprocessing', 'DummyApplication')) bci.Execute('Wait for Connected') bci.SetConfig() Here is how you import BCI2000Remote: File:BCIRemote.jpg Here is how you instantiate the operator object: File:BCIRemote 2.jpg Here is how to customize the operator and connect to it: File:BCIRemote 3.jpg Here is how you add your states: File:BCIRemote 4.jpg How to specify your signal source, signal processing, and application modules: File:BCIRemote 5.jpg How to connect and issue commands to BCI2000: File:BCIRemote 6.jpg And finally, how to tell BCI2000 to set states to a value during runtime: File:BCIRemote 6.jpg
  4. Now that you've added those components to your code all you have to do is run your code. You should see the BCI2000 operator along with the system log, source watcher, and the timing window. File:BCIRemote 7.jpg

C++ Tutorial

  1. Find your Python folder. If you have an existing Python environment with your code find it using the Sys Library like this: import sys locate_python = sys.exec_prefix print(locate_python)
  2. Locate your BCI2000Remote.py file which should have compiled into your prog folder.
  3. Find where in your Python code you wish to integrate BCI2000. In this example I will show the minimum requirements for integration with BCI2000: import sys sys.path.append('C:\\BCI2000\\prog') import BCI2000Remote bci = BCI2000Remote.BCI2000Remote() //print('Operator path:', bci.OperatorPath) bci.WindowVisible = True bci.WindowTitle = 'Python controlled' bci.SubjectID = 'pysub' bci.Connect() bci.Execute('cd ${BCI2000LAUNCHDIR}') bci.Execute('ADD STATE score 16 0') bci.StartupModules(('SignalGenerator', 'DummySignalprocessing', 'DummyApplication')) bci.Execute('Wait for Connected') bci.SetConfig() Here is how you import BCI2000Remote: File:BCIRemote.jpg Here is how you instantiate the operator object: File:BCIRemote 2.jpg Here is how to customize the operator and connect to it: File:BCIRemote 3.jpg Here is how you add your states: File:BCIRemote 4.jpg How to specify your signal source, signal processing, and application modules: File:BCIRemote 5.jpg How to connect and issue commands to BCI2000: File:BCIRemote 6.jpg And finally, how to tell BCI2000 to set states to a value during runtime: File:BCIRemote 6.jpg
  4. Now that you've added those components to your code all you have to do is run your code. You should see the BCI2000 operator along with the system log, source watcher, and the timing window. File:BCIRemote 7.jpg
  5. Video

    Also see the PsychoPy page for more details on the installation process, APIs, and hooks.


    See also