Send EEG triggers from OpenSesame via parallel port

For my all EEG paradigms I need to send marks (triggers) via parallel port to EEG to make a stamp when stimuli occurred and which one was that.

In my lab we use Biosemi ActiveTwo 64 active electrode system which can work only with 0-255 range of values. It means you can tag only 255 event types in your recording.

Cookbook

Ingredients

  • OpenSesame installed (tested on version 3.0)
  • Download dlportio.dll installer for Win-64bit (whole package contains testing paradigm)
  • Know you parallel port address (usually 0x378 or 0xCFF8)

Method

  1. Unzip downloaded dplportio driver. Run Install/InstallDriver.exe with admin.
  2. Copy dlportio.dll and paste it to the two locations a) root of installed OpenSesame and b) C:\Windows\SysWOW64

That is basically it. Just run OpenSesame and start new experiment. Add some sketchpads as fake stimuli (I named them stimA, stimB etc. to get experiment longer to properly see if triggers are working).

How to send triggers

First you can read a lot about initializing and sending EEG trigger by parallel port in OpenSesame on its website.

Initialize parallel port communication

First thing first. At the begging of your experiment you have to initialize a communication between OpenSesame and parallel port. This is done by initializing inline script which is regular in-line script at the top of your main procedure. Enter this code into preparation tab of in-line script.

try:
    from ctypes import windll
    global io
    io = windll.dlportio # requires dlportio.dll !!!
except:
    print 'The parallel port couldn\'t be opened'

 

This part of code initialize dlportio library which do the whole magic in writing bytes into you parallel port.

Null the port

After initialization I highly recommend to set parallel port value to 0 to prevent anything unwanted to be send (“ghost triggers”) from the whole begging.

All you need to do is enter another in-line script and write 0 to your parallel port like this:

global io
port = 0xCFF8
try:
    io.DlPortWritePortUchar(port, 0)
except:
    print 'Failed to send initial zero trigger!'

Or simply:

global io
io.DlPortWritePortUchar(0xCFF8, 0)

 

Write a byte

I guess need more than nilling the parallel port, so let’s look at how to send an integer value.

The method is basically the same but you have to set pulse duration and then set it back to the zero. This is done very similarly:

global io
trigger = 1
port = 0xCFF8
io.DlPortWritePortUchar(port, trigger)	# Send you trigger (int 1)
self.sleep(50)	# Uses trigger pulse for 50 ms
io.DlPortWritePortUchar(port, 0)	# Get back to zero after 50 ms

That it is. If you want to download my testing paradigm to test if your dlportio.dll was installed correctly or see how writing a byte to parallel port work, there is a link.

13 thoughts on “Send EEG triggers from OpenSesame via parallel port

  1. Ha, made it work!! What worked for me was what Jarik describes here: http://forum.cogsci.nl/index.php?p=/discussion/comment/7500#Comment_7500

    Then in OpenSesame I used the script as you show above to send the triggers. The Parallel Port Trigger plugin doesn’t work for me.

    Then it was tricky to figure out the port address. In E-Prime I simply select “LPT1”. I don’t have the Resources tab for the LPT port in Devices Manager, so I had to find it like this: Run C:\Windows\System32\msinfo32.exe, go to “Hardware Resources”, then “IO” and then I saw three entries for the Parallel Port, each showing a range of values, 0x00003000-0x0003FFF and two other ranges, so I had to try the starting address of each range. OpenSesame does not give any error or anything if I select a wrong address, I just don’t see any triggers in my EEG recorder SW. Finally, the third address worked, 0x3028 (you can skip the leading zeros).

    Like

  2. Hello Mike,

    Thank you for the wonderful blog post.

    I have three questions:
    1. Can Opensesame export triggers to USB port?
    I have Opensesame installed on a laptop with a USB port (no parallel port) and I want it to send triggers to a PC with Nihon Kohden EEG recorder.

    If we couldn’t achieve the synchronization between the experiment builder and the recorder. Would you recommend that we rely on time stamps (recorded by Opensesame and Nihon Kohden) for synchronization? This will be done offline, of course, after the experiment finishes and the files written to the respective computers.
    If we succeeded to install Opensesame on the same PC on which the EEG recorder (Nihon Kohden) is installed, do you know how I can get them to communicate in this case?

    Thank you very much for your time and concern.

    Like

    1. Hello Ahmad!

      Thank you for your interest in the blog 🙂

      Since it is Python based, why not? But this part may or may not cause you some time jitter in triggers based on your current HW.

      I would go for real time HW synchronization. Maybe I will write a post about what I am building with my college if I will have some time for it. I guess OpenSesame is basically realiable solution for most of your experiments. If you need timing (ERPs…) you have to choose different way I guess…

      Michael

      Like

      1. Hello Michael,
        Thank you very much for your reply. I am grateful for your concern.
        I have been doing some trials but I got stuck again, and I think I need to ask you a few simple questions. They are all related to the description of the setup shown in the video above.

        So, regarding the setup, this is what I understand:
        The setup is comprised of a PC and a laptop. The experiment builder is running on the PC. In the beginning of the video, you start the experiment on the PC and the fake stimuli (stimA, stimB, etc.) started to show up. Every stimulus writes an integer value to the parallel port.
        Then:
        As far as I understand, you use a parallel-port-to-usb converter and this is what you input to the laptop through a usb cable of course, right? The usb cable is shown in the video as a black striped cable with a silver tip at the end of the laptop, right?
        If all of the above is correct, does this mean that there is no “direct” cable or connection between the PC and the EEG unit? They are just both connected to the laptop?
        One last [silly] question: What is the software that was running on the laptop on which you showed us the sent triggers?

        I am thankful for your help, Michael. I am also relying on your willingness to help so I don’t promise that these will be my last questions 🙂

        Looking forward to hearing from you.

        Have a good one.

        Like

  3. Hi,
    I wanted to know if this will work for a similar device, fNIR (functional near infra-red) imaging device as far as sending triggers to the data acquisition software, or is this exclusively for sending data to EEG data acquisition software?

    Thanks,

    Like

  4. Hi Michael,
    Much thanks for all these information. The download link for “dlportio.dll installer for Win-64bit (whole package contains testing paradigm)” is not available, could you fix this please?
    Best,
    Amandine

    Like

  5. Hi Michael,
    Much thanks for these explanations! The download link to “dlportio.dll installer for Win-64bit (whole package contains testing paradigm)” is no longer available. Could you fix this?
    Best,

    Like

  6. Hi Amandine, unfortunately I don’t have a backup 😦 but hey are on the web. I also found that it is possible to use LPT OPpenSesame plugin which solves everything out-of-the-box withou installation.

    Like

Leave a comment