Remote Control and Other Programming Languages
Running Zapit stimuli in other programming languages or from a different PC
You can control Zapit from a different PC on the same network or from any programming language of your choice using the TCP/IP server. Make sure you are first familiar with Basic API Usage in MATLAB.
Controlling Zapit via TCP/IP
The easiest way to control Zapit externally is to use its built-in TCP/IP server. With this approach you can control a running Zapit instance from a different MATLAB instance on the same PC, a different programming language on the same PC, or from a different PC on the same network. You simply need to install the Zapit TCP Bridge on the client machine and correctly configure the Zapit YML settings file.
Configuring the YML file
Open the YML settings file and ensure tcpServer
enable
setting in the yml
file set to true
. If you will be controlling Zapit from an external PC, you must also set the IP
value in the settings file to the IP address on the PC which runs Zapit.
Find the IP address of the Zapit (server) PC with
zapit.interfaces.getIPaddress
Enter this into the TCP server
IP
variable in theyml
settings file.
Now save the YML file and re-start Zapit.
Connecting to Zapit using the TCP/IP client
Clone the Zapit TCP Bridge repo on your client PC. Go over the main README. At the time of writing the MATLAB client is the most mature, but there are also functional clients for Python and Bonsai. Read the examples for your desired client to get started. A brief example MATLAB session is shown below to give a flavour of what is possible.
Precise timing over TCP/IP
Precise stimulus timing is the same over TCP/IP as it is for local control of Zapit. The client PC will have DAQ that has a TTL line connected to PFI0 on the server (Zapit) PC. The following can then be used to present a randomly chosen 1 second stimulus that is triggered by the TTL line.
The stimulus rampdown begins after one second. If you set up an experiment path on the server, then stimulus identities are logged.
Rolling your own stimulus presentation code
The most low-level way to present stimuli in a language of your choice is to use the Zapit GUI for calibration but present the waveforms it produces using hardware and a language of your choice. It seems unlikely this option would be necessary, but the procedure for achieving it is outlined briefly below.
The Zapit GUI is used to make stimulus configurations and then calibrate the hardware so these can be presented in stereotaxic coordinates. All that is finally needed for this to happen is a small body of waveforms corresponding to each stimulus condition. The Zapit MATLAB API presents these waveforms and can be integrated into MATLAB code (or Python code via a wrapper). Not much work is needed to present these same waveforms in a different language. The example class in minimalWaveformPresentation demonstrates how to use the waveforms and stripped-down MATLAB code achieve this. There is substantial documentation. To use this above code:
Start Zapit and calibrate as normal. Load your desired stimulus set.
Then export the waveforms using the Export Waveforms button in the Sample Calibration tab, or at the CLI with the method
zapit.stimConfig.writeWaveformsToDisk
. Seehelp zapit.stimConfig.writeWaveformsToDisk
. You can run the command withhZP.stimConfig.writeWaveformsToDisk
.
The above should be enough information to get you started. But briefly, all you need to implement is code to:
Present the waveforms continuously using DAQmx at the correct sample rate.
Stop the waveforms with the gentle ramp-down. The ramp-down is generated in code and is not saved with the waveforms.
Log the identity of the presented stimuli.
Last updated