Re: [psychopy-users] pynetstation: which address and port to use

615 views
Skip to first unread message

Michael MacAskill

unread,
Nov 17, 2012, 7:50:22 PM11/17/12
to psychop...@googlegroups.com
Dear Tim,

I'm not familiar with your hardware or software, but a quick Google of the pynetstation docs seems to show that the connection is indeed a standard networking IP address and port combination, e.g from <http://code.google.com/p/pynetstation/wiki/ExampleIllustrated>:

# sample address and port -- change according to your network settings
ns.initialize('11.0.0.42', 55513)

I guess here '11.0.0.42' would be the IP address of the Mac running the software, and 55513 is the port number it is monitoring. i.e. each computer has a unique IP address on the network but has multiple networking ports on which it can listen for traffic: e.g. often port 80 is for HTTP web traffic. Your Netstation software will need its own specific port to operate on so that it doesn't conflict with other networking traffic. You should look inside the Netstation software on the Mac and see if you can find in its settings which network port number it is monitoring.

In this context, 'port' refers to networking terminology (think of ports as being the multiple apartments at a single street address: traffic gets sent to the street address/ IP address, but also needs a specific apartment number/port number to get to the right destination). It doesn't relate to hardware ports, like the Firewire and parallel ports. There might be separate commands to allow you to send/receive hardware events via the parallel port. But communicating indirectly with the software on the Mac may mean you don't actually need to talk directly to the EEG hardware via the parallel port?

Regards,

Michael


On 17 Nov, 2012, at 01:11, Tim Myers <timmy...@gmail.com> wrote:

> Hello, I am a first year graduate student, and new to Python and Psychopy. I have found Pyschopy to be a fantastic program so far and am very grateful to Jon and everyone else who have developed this. I am trying to connect my Psychopy program to EGI Netstation. Psychopy is on a PC desktop which is connected to the EEG amplifier through a parrallel port which connects to a Macbook Pro via a firewire port. The Netstation software is on the macbook. In the code to initialize pynetstation, it calls for an "address" and a "port". Does the address mean IP address and is it the address of the Macbook that is receiving the EEG data or the PC that is sending the Psychopy program info to EGI? Also, is the "port" the parallel port that the PC is sending from or the firewire port on the macbook that is receiving? Part of my code is below. I have put in bold the parts that relate to pynetstation. If anyone sees any other errors I have made besides what I have asked about, please feel free to point them out. Thank you very much for your time.
>
> import egi.simple as egi
> ms_localtime = egi.ms_localtime
> ns = egi.Netstation()
> ns.connect('address', port) #sample address and port -- need to verify and/or change
> ns.BeginSession()
> ns.sync()
> ns.StartRecording()
> continueRoutine = True
> while continueRoutine and routineTimer.getTime() > 0:
> # get current time
> t = Prac_stim1Clock.getTime()
> frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
> # update/draw components on each frame
>
> # *prac_stim1_one* updates
> if t >= 1.0 and prac_stim1_one.status == NOT_STARTED and number1 == 1:
> # keep track of start time/frame for later
> prac_stim1_one.tStart = t # underestimates by a little under one frame
> prac_stim1_one.frameNStart = frameN # exact frame index
> prac_stim1_one.setAutoDraw(True)
> # send marker to NetStation
> ns.send_event( 'evt_', label="event", timestamp=egi.ms_localtime(), table = {'st1w' :72} )

Message has been deleted

Tim Myers

unread,
Nov 18, 2012, 6:31:33 PM11/18/12
to psychop...@googlegroups.com

Michael,

Thank you very much for this information.  I am excited to get in the lab tomorrow to see if I can get this working.

With Regards,

Tim

Tim Myers

unread,
Nov 19, 2012, 9:02:20 AM11/19/12
to psychop...@googlegroups.com


Hello Everyone,

I wanted to write to follow up with my progress in case anyone else is trying to do the same thing and experiencing the same difficulties.  Michael was correct.  My initial confusion was that I thought "port" in the pynetstation module code meant a physical port (like a parallel port).  Instead it refers to the internal TCP/IP port that the NetStation software uses to communicate.  My NetStation software uses the default "55513".

However, the two computers I am using are connected via parallel port so now I am attempting, unsuccessfully so far, to use Parallel Python (aka pp) to activate the parallel port so that I can send my markers from the presentation computer to the computer with the NetStation software.

David McFarlane

unread,
Nov 19, 2012, 3:21:14 PM11/19/12
to psychop...@googlegroups.com
Um, once again stepping in where I probably don't belong... But are
you really trying to use Parallel Python to control the parallel port
using Python? I Googled "Parallel Python", and that got me to a
project page (http://www.parallelpython.com/ ) about providing a
"mechanism for parallel execution of python code on SMP (systems with
multiple processors or cores) and clusters (computers connected via
network)." That seems like an entirely different kettle of fish to me.

Thanks,
-- David McFarlane, Professional Faultfinder

Michael MacAskill

unread,
Nov 19, 2012, 3:39:23 PM11/19/12
to psychop...@googlegroups.com

On 20 Nov, 2012, at 09:21, David McFarlane <mcfa...@msu.edu> wrote:

> Um, once again stepping in where I probably don't belong... But are you really trying to use Parallel Python to control the parallel port using Python? I Googled "Parallel Python", and that got me to a project page (http://www.parallelpython.com/ ) about providing a "mechanism for parallel execution of python code on SMP (systems with multiple processors or cores) and clusters (computers connected via network)." That seems like an entirely different kettle of fish to me.

Yes, I think you are after another package. Here is a suggestion from previous e-mails, for a package that may or may not have been incorporated in PsychoPy in the meantime:


> Looks like this warrants some attention at my end.
>
> The package that Mike points to is provides complete source code (although without an explicit license) and doesn't need any fancy install process (unlike most kernel-level drivers) so it looks like this solution can be delivered fully contained within Standalone windows dist. :-) Should be easy to make psychopy.parallel calls use the inpuot32 lib as Mike shows below.
>
> And if I switch from winioport to pyparallel, it looks like we can add linux support for parallel ports too.
>
> I'll see what I can do.
>
> Jon
On 29/08/2011 22:44, Michael MacAskill wrote:
> Hi Martin,
>
> I recently wrote an experiment using psychopy.parallel to control a Polhemus Liberty electromagnetic movement tracker but wasn't able to test it before departing overseas as we still needed to have a cable fabricated. Anyway, in my absence, testing showed that psychopy.parallel didn't work for us and they switched to another method (successfully). Anyway, that preamble is to indicate that as I didn't implement it, I'm working backwards from the code so may not be giving you the right steer. But:
>
> <http://blog.wensheng.com/2008/10/python-parallel-port-on-windows.html> gives instructions for an alternative dll to download (inpout32.dll) and install. This may still be your limiting step though: no guarantees that McAfee won't get in the way again. We followed this route because psychopy.parallel wasn't giving us any joy, not because of virus warnings.
> More on inpout32 itself here:
> <http://logix4u.net/Legacy_Ports/Parallel_Port/Inpout32.dll_for_Windows_98/2000/NT/XP.html>
>
>
> Our code:
>
> try:
> from ctypes import windll
> p = windll.inpout32
> p.Out32(0xbd00,0)
> except:
> print "Could not import parallel library. Parallel port functionality disabled, so can't sync with Liberty"
> parallel_module_present = False
> else:
> parallel_module_present = True
>
>
> # amend as required to read from rather than write to the port. Use p.Inp32() ?
> def sendParallelTrigger():
> # on Windows, send a pulse to the Liberty software to indicate the onset of the first stimulus for synchronisation purposes.
> if (parallel_module_present):
> p.Out32(0xbd00, 255) # put all low on port 2-9
> core.wait(0.005) # 5 ms pulse duration
> p.Out32(0xbd00, 0) # Set all high
>

But anyway, I wonder if mucking about with parallel ports is really what you want to do. Wouldn't using the networking code as posted in your initial message be a much cleaner way to go? Networking comms tend to be much easier and more reliable than mucking about with hardware ports.

i.e. in your setup, your presentation PC (running PsychoPy) sends TCP messages (including events and timestamps) to the specified port on your Mac (running NetStation, and which is physically connected to the EEG via Firewire). i.e. it doesn't seem that the PsychoPy computer would need to have a direct connection to the EEG machine itself, as your event markers can get directly embedded into the NetStation recording data?

Regards,

Michael



Tim Myers

unread,
Nov 20, 2012, 7:16:06 AM11/20/12
to psychop...@googlegroups.com
David and Michael,

Thank you both very much.  That is extremely helpful.  No, David, you are most welcome to step in at anytime.  I appreciate you clearing that up as I am very new to setting up neurophysiological equipment.

Yes, I would actually rather send the signals via ethernet.  Currently, the stimulus presentation pc in our lab sends signals via the parallel port (it is set up to use Presentation software with NetStation).  When I tested my code above (in my first message) I received the message that the program timed out because it couldn't make a connection.  At this point, I assumed that this was because I didn't activate the parallel port in my code.  However, I have found another lab macbook that I could use so communicating through the firewire may be the best option.  I will try connecting that to see if I am able to send a marker.

I enjoy using Psychopy a lot more than Presentation so hopefully I can get this working.

Timothy

 

Michael MacAskill

unread,
Nov 20, 2012, 4:04:51 PM11/20/12
to psychop...@googlegroups.com

On 21 Nov, 2012, at 01:16, Tim Myers <timmy...@gmail.com> wrote:

> Yes, I would actually rather send the signals via ethernet. Currently, the stimulus presentation pc in our lab sends signals via the parallel port (it is set up to use Presentation software with NetStation). When I tested my code above (in my first message) I received the message that the program timed out because it couldn't make a connection.

On the Mac, you should check the Firewall settings in System Preferences> Security & Privacy. You probably want to turn off "Block all incoming connections" if it is set.

Also, on the Mac there is a utility called netcat (or nc) available from the Terminal which allows you to monitor traffic coming on a given port (type "man nc" for details).

e.g. type:

nc -l 55513

In that Terminal window, you will then see any messages to port 55513 which get sent through from your Python code on the PC, if a connection is made (I'm assuming its using TCP rather than UDP protocol). That could help simplify your testing rather than using the Netstation software itself.


Cheers,

Mike

Tim Myers

unread,
Nov 21, 2012, 11:59:07 AM11/21/12
to psychop...@googlegroups.com

Michael,

That is a brilliant idea.  Thank you very much.  That will be a much simpler way to test my connection.

Cheers,

Timothy 


Tim Myers

unread,
Mar 7, 2013, 5:47:02 AM3/7/13
to psychop...@googlegroups.com
Just writing to update.  Have worked on this for several months and I have not been able to find a way to get pynetstation to send markers to EGI Netstation.  The CAT 5 cable is good because the computers are able to ping each other.  However, when monitoring with either netcat or with Netstation own TCP/IP log, the operation always times out because no signals are being received.  If anyone has ever successfully used pynetstation, I would very much appreciate your input into how to send event markers.  A portion of my code is below.  The relevant pynetstation code is highlighted in yellow.  The place in the code where the process is getting stuck is highlighted in pink.  I am using the correct MAC address and port that Netstation is setup to receive.  I have verified with EGI technicians that I have everything set up properly on the Netstation side.

import egi.simple as egi

ns = egi.Netstation()

ns.connect('10.0.0.42', 55513)

ns.BeginSession()

ns.sync()

ns.StartRecording()

 

#------Prepare to start Routine"S1"-------

 

t = 0

S1Clock.reset()

# clock

frameN = -1

routineTimer.add(3.000000)

 

# update component parameters for each repeat

# keep track of which components have finished

S1Components = []

S1Components.append(Stim1)

for thisComponent in S1Components:

    if hasattr(thisComponent, 'status'):

        thisComponent.status = NOT_STARTED

 

#-------Start Routine "S1"-------

continueRoutine = True

while continueRoutine and routineTimer.getTime() > 0:

    # get current time

    t = S1Clock.getTime()

    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)

# update/draw components on each frame

# *Stim1* updates

if t >= 0.0 and Stim1.status == NOT_STARTED:
           

# keep track of start time/frame for later
        

    Stim1.tStart = t  # underestimates by a little under one frame
              

    Stim1.frameNStart = frameN  # exact frame index
           

    ns.send_event('evt_', label="event", timestamp=egi.ms_localtime(), table = {'st1w'

    :72}) #send signal to PyNetStation
           

    Stim1.setAutoDraw(True)
       

    elif Stim1.status == STARTED and t >= (0.0 + 3.0):

       Stim1.setAutoDraw(False)

 

# Uninitialize PyNetStation
       

ns.StopRecording()
        

ns.EndSession()
       

ns.disconnect

Luca Fortini

unread,
Jun 30, 2016, 5:36:57 PM6/30/16
to psychopy-users
Tim, I was wondering if you managed to send events to the Netstation software using Psychopy trough a TCP/IP protocol. I'm having the same issues you listed in this conversation
Reply all
Reply to author
Forward
0 new messages