UDP
UDP Broadcast allows you to send information from Pynapse to client software. Control values, Metric values, Session-related text, and custom text can be sent on the network. Enable UDP Broadcast on the General Tab.
UDP Broadcast Options |
Client classes for MATLAB and Python are available in the MATLAB and Python SDKs. See Programming Guide.
All UDP broadcast entries except for raw user text contain the session, block, and trial number.
Control Packet
Control values can be broadcast manually with the sendControlValue
method.
Example output
[1.1.2] Frequency=1000
Metric Packet
Metric values can be automatically broadcast when they change value. If Session Controls
are enabled and the metric is categorized as a Session, Block, or Trial metric, then
the metric value can also be broadcast at the end of that time period. They can also be
broadcast manually with the sendMetricValue
method.
Metrics UDP Options |
Example output
[1.3.4] Correct=2
Custom Text Packet
Use sendSessionEntry
to send text with the current session, block, and
trial number.
Example output
[2.1.2] my custom text
Use sendRawText
to send raw text (with or without a timestamp since the start
of the recording).
Example output
# with timestamp
00:09.91 raw text with no formatting
# without timestamp
raw text with no formatting
Methods
All UDP methods have the form p_Udp.{METHOD}
. Type p_
in the Pynapse Code Editor
and let the code completion do the work for you.
sendControlValue
p_Udp.sendControlValue(cname)
Broadcast a control value to the network prefixed with the current session, block, and trial number.
sendMetricValue
p_Udp.sendMetricValue(mname)
Broadcast a metric value to the network prefixed with the current session, block, and trial number.
sendRawText
p_Udp.sendRawText(strg, withTimeStamp=False)
Broadcast a custom string to the network.
sendSessionEntry
p_Udp.sendSessionEntry(strg)
Broadcast a custom string to the network prefixed with the current session, block, and trial number.
Programming Guide
MATLAB
You can download the latest MATLAB SDK files here.
The PynapseUDP class installs to:
C:\TDT\TDTMatlabSDK\TDTSDK\UDP
Example scripts install to:
C:\TDT\TDTMatlabSDK\Examples\UDP
Reading from Pynapse UDP
% instance of class that reads Pynapse UDP
u = PynapseUDP();
while 1
% block until next UDP packet received
u = u.read();
% print it
disp(u.data)
end
Python
The Python PynapseUDP class interfaces with Pynapse. It is available in the tdt pypi package (pip install tdt).
Reading from Pynapse UDP
import tdt
udp = tdt.PynapseUDP()
while True:
udp.recv()
if udp.data is not None:
print(udp.data)
udp.server.server_close()