Skip to content

PyNetStation_Code_Summary

Jin Jeon edited this page Dec 14, 2018 · 5 revisions

If you have basic understanding of how PsychoPy and NetStation communicate, you can use the summarized codes below to insert them to your own experiments.

Using PyNetstation module to connect with EGI NetStation

Below summarizes the core functions/components of PyNetstation module. Components primarily comprises of:

  • Initializing, connecting to NetStation
  • Trigger send event code
  • Disconnecting

It is referred several times throughout the module description, but it is best to use ns.sync() prior to any send_event codes.

Initializing and connecting to NetStation

import egi.simple as egi
ms_localtime = egi.ms_localtime # gives local time in ms 
ns = egi.Netstation() 
ns.connect('Enter IP Address', 55513) # Enter IP Address of NetStation machine/ Check on Multi-Port ECI Panel
ns.BeginSession()
ns.sync # Syncs the time between two machines 
ns.StartRecording()

Sending events

Insert the code below (sync and send_event) whenever you want to send signal to NetStation.
Note in ns.send_event, 'key', 'label', and 'description' must be in string format.
See at end to see details of ns.send_event.

ns.sync
ns.send_event(key='event key in 4 letter strings', 
              label="Practice", timestamp=egi.ms_localtime(), 
              description="Any additional info in string", 
              table={'Try#' : trialnum, 'resp' : var1, 'corr' : var2, 
              'ReaT' : var3, 'durr' : var4}, pad=False)
  • You can change table values as you want. These values will be printed out in port panel log as the NetStation is communicating with PsychoPy. Once the recorded file is saved, key, label, and table values will be saved out in event info of the resulted NetStation file. Note, the table is basically the Python dictionary form and the keys need to be 4 letter digits.

Disconnecting

ns.StopRecording()
#ns.EndSession() # this quits out netstation so commented out
ns.disconnect

From egi.simple:

def send_event(self, key, timestamp=None, label=None, description=None, table=None, pad=False):
        """
        Send an event ; note that before sending any events a sync() has to be called
        to make the sent events effective .
        Arguments:
        -- 'id' -- a four-character identifier of the event ;
        -- 'timestamp' -- the local time when event has happened, in milliseconds ;
                          note that the "clock" used to produce the timestamp should be the same
                          as for the sync() method, and, ideally,
                          should be obtained via a call to the same function ;
                          if 'timestamp' is None, a time.time() wrapper is used .
        -- 'label' -- a string with any additional information, up to 256 characters .
        -- 'description' -- more additional information can go here (same limit applies) .
        -- 'table' -- a standart Python dictionary, where keys are 4-byte identifiers,
                      not more than 256 in total ;
                      there are no special conditions on the values,
                      but the size of every value entry in bytes should not exceed 2 ^ 16 .
        Note A: due to peculiarity of the implementation, our particular version of NetStation
                was not able to record more than 2^15 events per session .
        Note B: it is *strongly* recommended to send as less data as possible .
        """