psychopy.org | Reference | Downloads | Github

Sending triggers to brainvision EEG system from Psychopy coderview

Hello there!

I am currently trying to get psychopy to send triggers to our brainvision EEG system through a parallel port we have installed on the task presentation computer.
I am having the hardest time getting psychopy to send triggers, as most solutions are in builder view, and we are working with coder view.

According to our device manager and a LTP port testing software, our parallel port’s address seems to be 3FF8.

Accodring to the posts already on discourse I have done/tried the following:

  1. I have downloaded the inpout32 and inpout64 drivers and put these into the same folder as my task script.
  2. I have found a script that allows one to send triggers using a trigger box & a serial port, but as this does not match our current set up, it does not work.
  3. The information at https://www.psychopy.org/api/parallel.html does not seem to work. When running a script with the recommended code, psychopy opens _inpout.py which crashes here… error

Has anyone had this problem before?
Alternatively, if anyone has an example script of a very simple experiment in psychopy coder that sends triggers to brainvision I would be eternally grateful!

Thanks!

Additional information: Here is the code that I was suggested to use for a serial port.

Even after modifying the code in the following way, the same error described in step 3 (above) occurs.

from psychopy import parallel 
port = parallel.ParallelPort(address='3FF8') 

Does anyone have an example of code where they successfully sent triggers via a parallel port?

Here are some notes from my tests to send triggers for a PC with a parallel port to an Actichamp EEG system.

Tools
Parallel port tester http://www.downtowndougbrown.com/2013/06/parallel-port-tester/.
Parellel port tester need InpOut32 or InpOut64 http://www.highrez.co.uk/downloads/inpout32/default.htm.

Test parallel communication
Connect presentation PC to ActiChamp using the parallel port.

On acquisition PC

  • Launch BrainVision Recorder.
  • Open menu "Amplifier > Digital Port Settings… Set “Bits are” to “high active”.

On the presentation PC

  • Run “Parallel Port Testing”.
  • Change port 0 to 7 state.

On the acquisition PC side, in the window “Digital Port Settings” the “Current state” should change accordingly.

The application “Parallel Port Testing” also show the address of the parallel port used.

No need to switch to PsychoPy as long as the communication via the parallel port does not work.

Coding triggers

I haven’t been able to send triggers using the parallel_port_trigger module.

I used the “dportio.dll”.

Here are the code parts I used. It was with OpenSesame but it should also work with PsychoPy.

At the beginning of the experiment.

# Init parallel
try:
    from ctypes import windll
    global io, parallel_port
    io = windll.dlportio # requires dlportio.dll !!!
    parallel_port = 0x378
except:
    print('The parallel port couldn\'t be opened')

Then, whenever necessary, it is necessary to send a signal by setting one or more bits to 1, then setting it to 0.

Note: The trigger signal must be present for at least the duration of one sampling (1 ms for sampling at 1000 Hz, 2 ms for 500 Hz, etc.).

This is done with the following code.

global io, parallel_port
trigger = 1
try:
    io.DlPortWritePortUchar(parallel_port, trigger)
except:
    print('Failed to send trigger!')

Make the script wait some time an then set back the trigger to 0.

global io, parallel_port
trigger = 0
try:
    io.DlPortWritePortUchar(parallel_port, trigger)
except:
    print('Failed to send trigger!')

I’ll try to find some time to access to the EEG system to test the code with PsychoPy.

Hi ypohcysp!

Thanks for the fast reply!
I’ve given your suggestions a try, but have not been successful in using the code you have suggested to send triggers. Actually, the code does not seem to even establish communication with the parallel port.

The first part of what you recommended worked great! Here is what the parallel port tester looks like when I open it and select ours:


As suggested when toggling the D0 port to green, this changes the digital port settings on the acquisition computer.

Sending triggers
As your code requires dlportio.dll, I downloaded this, put it in the same folder as my experiment (as previously done with the inpout drivers), as well as followed the instructions on www.dlldownloader.com/dlportio-dll on how to download it.

I then copy/pasted your recommended code to the start of my psychopy code, changed the address to 0x3FF8 (which is the address according to the parallel port tester), and ran the code.
code

Although the task does not crash, it always prints ‘The parallel port couldn’t be opened’. Psychopy prints this error if I use ‘3FF8’ as the address as well.

The last thing I tried, is following the Method 1 and 2 steps for troubleshooting with dlportio.dll at: www.dlldownloader.com/dlportio-dll. This did not solve the problem as the same message is always printed in psychopy.

Were you able to try the code out on psychopy on your system? If so, did it work?
What am I doing wrong?

Thanks again for all your help with this!

Alexa