Skip to content

Run Experiment For Set Duration

This examples shows how to use Python to control the Synapse mode and monitor recording status.
This uses the 'ExperimentSetTime' example experiment, but it could run with any experiment.

Housekeeping

Import tdt library for SynapseAPI, and Python's built-in time library so we can add a pause

import time
import tdt

Setup

Choose which experiment to run and the duration. It could be anything.
This example uses a simple experiment with just a Tick store.
To see full list of available experiments use syn.getKnownExperiments()

EXPERIMENT = 'ExperimentSetTime'
TOTAL_TIME = 30

# Connect to Synapse
syn = tdt.SynapseAPI()

# Set your experiment
syn.setCurrentExperiment(EXPERIMENT)

Runtime

# Set the system to 'Preview' mode
syn.setModeStr('Preview')

# Wait five seconds to give 'getSystemStatus' time to update internally
time.sleep(5)

Main Loop

currTime = 0
prevTime = 0

# Poll the system status until it reaches the desired state
while currTime < TOTAL_TIME:

    # Add any additional API controls here
    currTime = syn.getSystemStatus()['recordSecs']
    if prevTime != currTime:
        print(f'Current elapsed time: {currTime}s')

    prevTime = currTime
Current elapsed time: 3s
Current elapsed time: 4s
Current elapsed time: 5s
Current elapsed time: 6s
Current elapsed time: 7s
Current elapsed time: 8s
Current elapsed time: 9s
Current elapsed time: 10s
Current elapsed time: 11s
Current elapsed time: 12s
Current elapsed time: 13s
Current elapsed time: 14s
Current elapsed time: 15s
Current elapsed time: 16s
Current elapsed time: 17s
Current elapsed time: 18s
Current elapsed time: 19s
Current elapsed time: 20s
Current elapsed time: 21s
Current elapsed time: 22s
Current elapsed time: 23s
Current elapsed time: 24s
Current elapsed time: 25s
Current elapsed time: 26s
Current elapsed time: 27s
Current elapsed time: 28s
Current elapsed time: 29s
Current elapsed time: 30s

Our desired elapsed time has passed, switch to Idle mode

syn.setModeStr('Idle')
print('done')
done