EEG: Connecting psychopy to EGI station (time.out error)

Hello all,

I am trying to connect my experiment to the EGi station of the EEG. I used the code provided here
Sending triggers via EGI NetStation — PsychoPy v2022.2.4. When I start my task I get an error:

File… egi/pynetstation/Netstation.py, line 138, in connect self._socket.connect()
File…egi/pynetstation/socket_wrapper.py,line 38, in connect self._socket.connect(self.address)
socket.timeout: time out
Experiment ended with exit code 1 [pid:3528]

Anyone that has some idea what this is about?
Thank you in advance for your help.

My best regards,
Anastasia

Also another detail: I do not have internet connection on the computer i am using could this be a problem?

Hello,

Happy to try to debug this with you. First need a bit more information on your setup.

  1. Which EGI amplifier are you using? 300 or 400?
  2. What version of Net Station are you using?
  3. Can you provide us with your connect code from the PsychoPy experiment?
  4. Can you provide a screenshot of your network system preferences with IP address and subnet mask for both the Net Station computer and the stimulus presentation computer?
  5. Have you been able to use other stimulus presentation systems in the past? E-PRIME or Matlab (i.e. psychtoolbox)?

-Peter

Hello Peter,

Thanks for your response and help.
Here are the details:

  1. High-impedance amplifier Net Amp 400
  2. Net Station Software 4.3
  3. The code I used:

“C:\Program Files\PsychoPy\python.exe” -m pip install egi-pynetstation"

#Import Netstation library
from egi_pynetstation.NetStation import NetStation

#IP address of NetStation -
IP_ns = ‘10.0.0.51’

#IP address of amplifier
IP_amp = ‘10.0.0.42’

#Port configured for ECI in NetStation -
port_ns = 55513

#Start recording
eci_client = NetStation(IP_ns, port_ns)
eci_client.connect(ntp_ip = IP_amp)
eci_client.begin_rec()
eci_client.send_event(event_type = ‘STRT’, start = 0.0) "

  1. I am not at the moment in the lab (i will take a screenshot asap) but the IP adress of the system is 10.10.10.51

  2. Yes it works fine both with psychtoolbox and E prime.

i am also using Python 3 and the latest version of Psychopy.

Thanks again for your help.

Anastasia

Hi Anastasia-

I think the hiccup may be the reversal of the AMP and NS (Net Station) IP addresses. Try changing:

IP_ns = ‘10.0.0.42’
IP_amp = ‘10.0.0.51’

You can double check this info in the webpage on the Net Station computer that connects to the amplifier (below) where the Network address of the amplifier is shown as “Network Address” and the Net Station address is shown as “Client Address”.

Let me know if this solves the issue.

One other tidbit is that the last line eci_client.send_event(event_type = ‘STRT’, start = 0.0) will send an event at the beginning of the recording (time from beginning of recording is the argument). But for most purposes you can just provide the event_type and omit the start argument for the message to be sent “now”. Being able to specify the time allows you to add a marker from the beginning of the recording file like to add a response or trial evaluation (e.g. correct, incorrect) after the fact.

There’s a tiny bit more information on our github page GitHub - nimh-sfim/egi-pynetstation: Python package to enable the use of a Python-based API for EGI's NetStation EEG amplifier interface., as well as an example.py that might be of some use.

-Peter

1 Like

Hello Peter,
thank you for the suggestions I am currently out of the lab but I will try them out
Monday morning and also check the github page.
For the first solution I am pretty sure that the IP adresses were correct but I can try out to reverse them.

I will post my progress here.

Thanks a lot,
Anastasia

Hello Peter,

I tried a second attempt by removing the start from the the send event but I get a similar error.
The error is located in the function socket.py and in specific in the life self.socket.connect(self._address).
The specific error is Winerror 10051: A socket operation was attempted to an unreachable network.

In the code section of the socket_py there is the self._address = (address,port) could it be that I need to specify the address as the IP of the stimulus PC and the port as the serial number of the port of the net station?

Thank you in advance!
Ana

hello again Peter,
I can happilly say that I made it work! I was something related to the IP address of the stimulus computer!
but it connects succesfully now and I hope the triggers will work too.

1 Like

Great to hear that it’s working! Let me know if you have any issues with timing. Always good to run a timing test with the EGI photo diode or audio cables to ensure that you have stable timing of the stimuli over the course of the experiment. Sending an occasional resync() often helps this and we often place it at the beginning of a trial.

1 Like

Hey Peter,
thanks for the tip on the resync.
I have a questions regarding the triggers. I am using this code

if image.status == STARTED and not stimulus_pulse_started: #Change ‘stimulus’ to match the name of the component that you want to send the trigger for
win.callOnFlip(eci_client.send_event, str.encode(‘imag’))

and imag is the variable name fir ann image component defined in an excel file but it does not work. Although it work if I just put the name of the image component but I would like to have a specific trigger for each category of the images.

I would like to ask if there is any specification on how to set specific trigger? Cause the general code works but Icouldnt find more intructions from the forum apart from the one I tries above.

And last thing the trigger for the response component it does not work at all. Is there a separate way to set trigger for responses?

if response.status == STARTED and not stimulus_pulse_started: #Change ‘stimulus’ to match the name of the component that you want to send the trigger for
win.callOnFlip(eci_client.send_event, event_type=‘resp’))

Thank ina dvance for any answer,
My best
Anastasia

I’ll test this tomorrow when I have time on our system. But briefly:

  1. The send_event(event_type) needs to be a 4 character representation. So you likely need to add another column in your excel file to create a simplified name for the stimulus. Other fields of the stimulus (e.g. label, description, data) can be longer.

  2. For responses, I think you want that to happen immediately upon receiving the response. If your response terminates the routine you can just put it in “end routine” as a standard send_event( ). Importantly, just like above you can send other characteristics like a label, description, and event a data array along with it. Alternatively (if your response doesn’t end a routine) you can have the script check “each frame” like the original and detect Object.keys > 0 to decide to send a response. You likely want to have a second version of stimulus_pulse_started (e.g. response_pulse_sent) to check for the response sent in this case… but I don’t use one in my own code since all I care about is the first response.

1 Like

Thanks a lot for the reply!
I tried making the event type a variable like so: send_event, event_type =‘$trig’ and I defined trig in my loop excel file with nothing exceeding 4 words. But it does not recognize it is a variable, it says that my event name is 5 chr so it icnluded ‘$’ as a character. I tried also without ‘’ ‘’ but nothing changes.How can I define it as a variable?

For the response I added it in the end of the routine with the same code as

if key_resp.status == STARTED and not triggerSent:
win.callOnFlip(eci_client.send_event, event_type=‘resp’))

but still nothing happens.

Ok I figured a way,
I left event_type as it is and added label =trig and trig defined in my excel file
and it worked and recognized each label but the same did not work for event_type I don’t know why.

I still miss the responses triggers so any other suggestion would be very much appreciated but thank you immensely for all the tips

Glad you’ve made progress on getting your triggers to work!

For responses, try to take the function call at EndRoutine out of the CallOnFlip:

eci_client.send_event('resp')

1 Like

I’ve taken the basic Stroop experiment and modified it to have EGI calls. Hopefully this helps with some of the confusion!

stroopEGI.zip (6.7 KB)

1 Like

Hello,

Thanks a lot. The rensponses work perfectly with this code as well!
Thanks for creating the paradigm!

Hello again Peter,

i run a test for my timign test with a photodiode but the variability of the tiing between the trigger
of psyhcopy and the photo diode is very large and is getting larger as the experiment advances with a negative offset (so the triggers fro psychopy arrive later). Any advice on why would that be the case?
And a question about the pynetstation clock, the clock for the task used is it the one of the amplifier or I need to specify it in the beginning? Thank you again veyr much
Best
Anastasia

Hello,

You’ll need to run the eci_client.resync() command every trial or so. I usually put this command into the “begin routine” part of the trials code. Our package only uses NTP clock timing based on the amplifier, so you don’t need to specify anything else.

If you still see highly variable timing after adding the resync(), then it would be good to get info on the rest of your setup. Let us know the make/model/OperatingSystem of your stimulus presentation computer, the type of monitor you’re using, the networking setup, and any other details. Feel free to attach photos (lots of them).

Common things that can cause issues with timing are (in no particular order):

  1. Monitor/video splitters that duplicate the image on two displays
  2. Background processes on the stimulus presentation computer
  3. Unsupported or out of date drivers for the computer’s video card
  4. Extremely long experiments

-Peter

Hello again,

I just tried adding the resync in each begin routine but i get the same results.
We do have two monitors one outside that runs psychopy and one inside the EEG room to which duplicates the task.(image attahced). Both work in windows while the net station laptop is mac.
The Net station is connected with amplifier and all the computers/moniter in a closed network with a black box. (image attached).
I am attaching also the resutlts of the timing test.
what qualifies as a long experiment? Mine is at least 40 minutes i guess and the timing gets worse towards the end.