Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Every N Samples Callback with AO channels (PCIe-6321)

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

0 Kudos
Message 1 of 3
(5,207 Views)

Can you reproduce this in C, a .NET language or LabVIEW? We did not implement the PyDAQmx wrapper, so I just want to make sure the issue can be reproduced with a supported implementation of the driver. If it is an issue with the wrapper, I would suggest contacting the developer of PyDAQmx.

William R.
0 Kudos
Message 2 of 3
(5,178 Views)

I don't have a LabVIEW license and I'm not setup to compile C programs. However, I was able to find a work-around. The trick is to write some samples to the buffer first and then commit the task. Why would this be the case for X-series but not for M-series?

0 Kudos
Message 3 of 3
(5,079 Views)