Synapse Control
Pynapse has built-in slots for Synapse mode change events. These are useful in the 'Always' state to initialize variables or buffers for stimulation before the recording begins. It also has a built-in instance of SynapseAPI to control other gizmo parameters from Pynapse.
Slot Methods for Responding to Synapse Mode Changes
These slots capture Synapse system mode change events. They are available as method definitions inside Pynapse states. Write a method with this name to react to the corresponding mode change event.
Important
If you use p_State.switch() inside s_Mode_standby(), this overrides the 'Initial State' setting on the
General Tab.
Example
Preload a stimulus output buffer before the experiment runs
import numpy as np
class Always: #StateID = 0
def s_Mode_standby():
import random
p_Output.MyOutput.setBuffer(np.random.random(1000).tolist())
When experiment starts, switch to PreTrial state as the default starting state.
class Always: #StateID = 0
def s_Mode_standby():
p_State.switch(PreTrial)
SynapseAPI
Pynapse also exposes an instance of the SynapseAPI class in two different ways for your convenience.
Type api. in your Code Editor and the code completion will show you a list of objects in the Processing
Tree that have API parameters. Once you've selected that, the code completion shows you the parameters
inside. Then you can use read and write to access them. For example, if you want to trigger
a separate audio stimulation gizmo from Pynapse using the api, you can type:
api.ufStim1.Strobe.write(True)
As you type, autocomplete will help you find the gizmo and parameter that you're looking for.
The full SynapseAPI is also available from the variable syn in the Code Editor. Type syn.
and code completion shows you all of the available method calls. For the complete list of
SynapseAPI methods and how to use them, see SynapseAPI Manual.
Note that in the above example, the following calls are equivalent:
syn.setParameterValue('ufStim1', 'Strobe', True)
api.ufStim1.Strobe.write(True)
However, with syn. you would have to look up or remember the gizmo name and parameters. Use api. to
have that heavy lifting done for you.
Important
SynapseAPI calls go through sockets, and that adds some extra delay. The SynapseAPI calls are also affected by what is happening in the Synapse window. For example, if you do something that is graphically intensive such as resizing the windows during a recording, you can see a big (>100 ms) lag before the call gets through. It shouldn't be relied on for time critical events.
Example
User puts system into Standby mode, then when trigger is received Pynapse switches system to Record mode.
class Always: #StateID = 0
def s_MyInput_rise():
syn.setModeStr('Record')