I am unable to get the EveryNSamples callback working with analog outputs (i.e., DAQmx_Val_Transferred_From_Buffer). I can get it working using analog inputs (i.e., DAQmx_Val_Acquired_Into_Buffer). I have successfully used this code on M-series hardware; however, I'm trying to get it to work on newer X-series harware (specifically, the PCIe-6321). This code is in Python (using PyDAQmx as the wrapper). the first segment of code (which sets up an every N samples callback for analog inputs) works fine. The second segment of code (which sets up an every N samples callback for analog outputs) fails with error code -88700. I need to get this callback working with analog output, so I'd appreciate any pointers:
def nsamples_callback(task, event_type, n_samples, data):
print 'called'
return 0
mx.DAQmxResetDevice('Dev2')
ai_task = mx.TaskHandle()
mx.DAQmxCreateTask('', ctypes.byref(ai_task))
mx.DAQmxCreateAIVoltageChan(ai_task, '/Dev2/ai0', '', mx.DAQmx_Val_RSE, -10, 10, mx.DAQmx_Val_Volts, '')
mx.DAQmxCfgSampClkTiming(ai_task, '', 20e3, mx.DAQmx_Val_Rising, mx.DAQmx_Val_FiniteSamps, int(100e3))
cb_ptr = mx.DAQmxEveryNSamplesEventCallbackPtr(nsamples_callback)
mx.DAQmxRegisterEveryNSamplesEvent(ai_task, mx.DAQmx_Val_Acquired_Into_Buffer, 10000, 0, cb_ptr, None)
mx.DAQmxTaskControl(ai_task, mx.DAQmx_Val_Task_Commit)
The following code generates an error:
def nsamples_callback(task, event_type, n_samples, data):
print 'called', task, event_type, n_samples, data
return 0
mx.DAQmxResetDevice('Dev2')
ao_task = mx.TaskHandle()
mx.DAQmxCreateTask('', ctypes.byref(ao_task))
mx.DAQmxCreateAOVoltageChan(ao_task, '/Dev2/ao0', '', -10, 10, mx.DAQmx_Val_Volts, '')
mx.DAQmxCfgSampClkTiming(ao_task, '', 20e3, mx.DAQmx_Val_Rising, mx.DAQmx_Val_ContSamps, int(1e3))
cb_ptr = mx.DAQmxEveryNSamplesEventCallbackPtr(nsamples_callback)
mx.DAQmxRegisterEveryNSamplesEvent(ao_task, mx.DAQmx_Val_Transferred_From_Buffer, 1000, 0, cb_ptr, None)
mx.DAQmxTaskControl(ao_task, mx.DAQmx_Val_Task_Commit)
The error is:
DAQError: An internal error occurred.
Task Name: _unnamedTask<1>
Status Code: -88700
in function DAQmxTaskControl