Psychopy to egi netstation connection error?

Hello,

I posted the issue last week, but came back with clearer question. So I’m having difficulty establishing connection between the Psychopy running testing machine and the machine with the actual netstation installed. I numbered the summary questions at bottom!

I have the basic following code below, but I’m assuming I am inputting a wrong IPv4 address or port number for the net station.

from __future__ import absolute_import, division, print_function
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging,     clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                            STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
               sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions
import sys  # to get file system encoding

# Setup for EGI 
import egi.simple as egi # for testing purposes
#import egi.simple as egi
ms_localtime = egi.ms_localtime # gives local time in ms 
ns = egi.Netstation() 
ns.connect('ipv4 address of the testingmachine ', 'port number of netstation machine') # change/ check by Network Utility?

And I get the following error:

File "/Users/abc/Documents/PsychoPy/cfv/cfv_egi.py", line 281, in ns.BeginSession() 

File "/Users/abc/Documents/PsychoPy/cfv/egi/simple.py", line 799, in       BeginSession self._socket.write( message ) 

File "/Users/abc/Documents/PsychoPy/cfv/egi/socket_wrapper.py", line 58, in write self._connection.write( data )
AttributeError: Socket instance has no attribute '_connection' 6.9777 WARNING 

When I change the port to another one with a server, it gives me the below:

Traceback (most recent call last): File    
"/Users/abc/Documents/PsychoPy/cfv/cfv_egi.py", line 281, in ns.BeginSession() 

File "/Users/abc/Documents/PsychoPy/cfv/egi/simple.py", line 804, in BeginSession return self.GetServerResponse() 

File "/Users/abc/Documents/PsychoPy/cfv/egi/simple.py", line 783, in GetServerResponse 
raise Eggog( "unexpected character code returned from server: '%s'" % (code, ) ) 
egi.simple.Eggog: unexpected character code returned from server: 'R'

So summarizing my question,

  1. Is it correct that I am supposed to input the IPv4 address of the NetStation machine?
  2. how do I figure out what port number I need to input? Do I use the port numbers listed from using “Network Utility” app in the mac?
  3. When running the psychopy code that makes me connect to the machine, what needs to be setup in the Netstation computer? ie. do I need to have netstation software running?

Thank you. Any help or pointers would be appreciated!

Hi Jin,

A few things (numbered to match your questions):

  1. Yes, use the IPv4 address of the NetStation computer. If you bought the NetStation computer directly from EGI then they probably assigned it to one of their standard static-IP addresses (10.0.0.42, 10.10.10.42, etc.). Is there a static IP address set up on your NetStation computer? It should look like this example under Network Preferences (except 0.0.0.0 is your static IPv4)
  2. You probably don’t need to worry about your port number as that’s almost never changed (unless you’re doing some highly customized hardware integration). 55513 should suffice.
  3. Yes, if NetStation must be running–a session must be open, and it should be showing lines on the screen to match your electrodes. It doesn’t need to be recording, just open and ready to record when you want it to. Open the TCP/IP Log and watch as you run your script to see if you’re getting the “handshake” message when your script runs the ns.connect("11.0.0.42", 55513).
    Extra:
  4. If you didn’t know this already, the ns.connect() command should have 2 values. The first value should be your NetStation IP address as a string object. If you don’t know what that means, just surround your IP address with qoutation marks (""). The second value must be an integer. Make sure it does not have quotation marks (as you have supplied above in your example code).
  5. PyNetstation hasn’t been tested with Python 3 yet so if you’re using PsychoPy based on Python 3, it probably won’t work (yet). Let me know if that’s the case.

Hope that helps.

Best,
Josh

1 Like

Hey Josh,

Thanks for replying!! Yes, I tried as you mentioned, using the IP address of the netstation machine, and inserting port numbers as 55513 or even tried other port numbers just to make sure (I also took out the ’ ’ for port values). I also had a random session of netstation up and running, without having any net or record plugged.

Unfortunately, I still get the same error:

File "/Users/abc/Documents/PsychoPy/cfv/cfv_egi.py", line 281, in ns.BeginSession() 

File "/Users/abc/Documents/PsychoPy/cfv/egi/simple.py", line 799, in       BeginSession self._socket.write( message ) 

File "/Users/abc/Documents/PsychoPy/cfv/egi/socket_wrapper.py", line 58, in write self._connection.write( data )
AttributeError: Socket instance has no attribute '_connection
  1. I am using PsychoPy2 with Python 2.7 and the netstation 4.3.1. Do you think using the this old version could cause a problem?

  2. As for checking the “handshake message”, how can I exactly do it? Should I get into the console.app and check the reports from the device? I couldn’t get any message. Also, you mentioned as ns.connect("11.0.0.42", 55513). This 11.0.0.42 needs to be replaced with my IP address? Just double checking.

– just few more notes,
I’m new to the netstation and using Pynetstation. So, if I send a certain data upon keypressed in the PsychoPy, how is the information displayed on the netstation interface? (ie. is there like a workspace that prints out the info?)

Sorry for so much questions!

  1. The package has been tested and functional for Netstation 4.4.x, 4.5.x, and 5.2.x. I don’t think there were any changes between 4.3 & 4.4 that would have broken compatibility, but I don’t have a copy of 4.3 to test that with.
  2. The handshake is in the TCP/IP Log within NetStation. To open it go to “Panels” on the Menu Bar and select TCP/IP Log.

    This is where you’ll see information about connecting the 2 computers as well as information relating to the events you’re sending (button presses, trial number, etc.) which you send using the ns.send_event() method.

What I’m noticing here is your error is from a call to ns.BeginSession(), which should only be called after ns.connect(). Is that how you have it set up? The error essentially is saying that you haven’t created an object property self._connection which only gets created when you run the ns.connect() method. If you do have the connect method before the BeginSession method, then it means you aren’t actually connecting to the NetStation computer at all.

From there, you’ll want to check

  1. your ethernet cable is connected well between stim presentation computer and NetStation computer
  2. your NetStation software is running and scrolls lines across the screen (regardless of whether there is a net attached or it is actively recording).
  3. your stim presentation computer has a static IP address set to a similar address as the NetStation computer (but not the exact same, one number higher. Example: NetStation IP=11.0.0.42; PsychoPy computer IP=11.0.0.43)

Try some of those out and let me know what happens.
Best,
Josh

1 Like

Hey Josh,

Thanks for the detail picture with the panel. On 4.3.1, I don’t think there’s a separate panel for TCP/IP Log. These were the only options. I tried searching through different menu but couldn’t find anything. Picture%206

As for the code, yes the ns.BeginSession() is located way after ns.connect() is being made.
Maybe it is the ethernet cable connection?
1&3. So, for the original setting, the stim computer and NetStation computer seemed to be shared via router instead of being connected directly with ethernet cable (They’re lab computers and each ethernet cable go into some hole, but in both of their network menu, they share the same router IP address). At this state, stim computer has IP of X.X.X.150 and NetStation computer IP is X.X.X.23.
If I make a new cable that connects from stim computer to NetStation computer, IP changes to X.X.X.15 and X.X.Y.71 which are different, and still get the same AttributeError: Socket instance has no attribute '_connection' error.

  1. NetStation runs fine. The lines keep running across the screen.

Thanks for helping me out. This is such a pain not knowing what’s really going wrong :frowning:

-----Self-update:

I fixed the problem by configuring the setup on NetStation software. Turned out that there was nothing wrong with the code. I didn’t have the workspace configured to take the “stimulator” device connected to the NetStation.

As for the code, I changed just the IPv4 address of my NetStation machine and left the port number as default.

Thanks Josh for the help! I realized my workspace didn’t have the ‘TCP/IP’ Panel, and started working in reverse from that.

1 Like