To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/7fd4945c-1e71-4159-a266-95f53e3f42eb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
python setup.py installfrom __future__ import print_functionimport nidaqmximport numpy as np
NIDEVICE = 'Dev1'AOPORT = NIDEVICE + '/ao0'
SAMPLE_RATE = 100000 # HzTRIGGER_LENGTH = 500 # samples, i.e. 5 ms
device = nidaqmx.libnidaqmx.Device(NIDEVICE)device.reset()
analogOutputTask = nidaqmx.AnalogOutputTask(name='MyAOTask')analogOutputTask.create_voltage_channel(AOPORT, channel_name='ao0', min_val=0, max_val=5, units='volts')
# The idea is to write 500 +5 V samples (5 ms trigger), followed by a single 0 V sample (trigger off)
#triggerPulse = 5 * np.ones(TRIGGER_LENGTH + 1)triggerPulse[-1] = 0
analogOutputTask.configure_timing_sample_clock(rate=SAMPLE_RATE, sample_mode='finite', samples_per_channel=TRIGGER_LENGTH + 1)
# We prepare the buffer, but don't start the generation yet.samplesWritten = analogOutputTask.write(triggerPulse, auto_start=False)
print('Wrote', samplesWritten, 'samples to buffer.')
# We can do other fancy things just here
# ...
#
# Now, let's send the trigger!analogOutputTask.start()
# This line should be taken out in a real experiment,
# as it would block until the card has finished
#analogOutputTask.wait_until_done()
del analogOutputTaskimport nidaqmxfrom psychopy.core import wait
NIDEVICE = 'Dev1'DOPORT = NIDEVICE + '/port0/line0'
device = nidaqmx.libnidaqmx.Device(NIDEVICE)device.reset()
digitalOutputTask = nidaqmx.DigitalOutputTask(name='MyDOTask')digitalOutputTask.create_channel(DOPORT, name='line0')
digitalOutputTask.start()
for i in range(10): # Set DO port to HIGH digitalOutputTask.write(1) wait(1, hogCPUperiod=1) # Set DO port to LOW digitalOutputTask.write(0) wait(1, hogCPUperiod=1)
# Stop DO signal generationdigitalOutputTask.stop()del digitalOutputTaskanalogOutputTask.write(triggerPulse, auto_start=False)
# Prepare stimuli here# ...
# Send the trigger as the visual stimulus is presentedwin.callOnFlip(analogOutputTask.start)win.flip()
# Do random stuff here# ...
# Stop the task, so we can at a later point write() and start() it again if desired.analogOutputTask.stop()
del analogOutputTaskdigitalOutputTask.start()
# Prepare stimuli here
# ...
# Set DO port to HIGH as soon as the visual stimulus gets presented
win.callOnFlip(digitalOutputTask.write, 1)
win.flip()
# Now, set DO port to LOW again
digitalOutputTask.write(0)
# Do random stuff here
# ...
# Stop DO signal generation
digitalOutputTask.stop()
del digitalOutputTask