Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

The DAQmxSetBufOutputOnbrdBufSize function cannot be called during CreateDOChan

I encountered an issue while using NI's C language API library. After creating a DO task with the DAQmxCreateDOChan function, I called DAQmxSetBufOutputOnbrdBufSize, and an error occurred when starting the task.  The program runs normally if I do not call DAQmxSetBufOutputOnbrdBufSize. 

 

The error message is as follows:
DAQmx Error: The software has entered an unknown state - usually as a result of a cascade failure induced by an unexpected series of state inputs. The operation could not be completed as specified and you should immediately terminate all further transactions if you are able to do so.
Task Name: _unnamedTask<1>
Status Code: -50150

 

Here is my code:

TaskHandle pulse_task_handle = 0;
do
{
uInt8* buffer = new(std::nothrow) uInt8[CALLBACK_COUNT * line_count];
if (buffer == nullptr) { error = (int32_t)(NI_LIB_ERROR::MALLOC_FAILED); break; }
 
_output_buffer = buffer;
 
//configure task
error = DAQmxCreateTask("", &pulse_task_handle);
if (DAQmxFailed(error)) { break; }
 
_task_handle = pulse_task_handle;
 
error = DAQmxCreateDOChan(pulse_task_handle, concat_line_names.c_str(), "", DAQmx_Val_ChanPerLine);
if (DAQmxFailed(error)) { break; }
error = DAQmxSetWriteRegenMode(pulse_task_handle, DAQmx_Val_AllowRegen);
if (DAQmxFailed(error)) { break; }
int32_t activeEdge = _is_sync_valid_high ? DAQmx_Val_Rising : DAQmx_Val_Falling;
error = DAQmxCfgSampClkTiming(pulse_task_handle, "", SAMPLE_RATE, activeEdge, DAQmx_Val_ContSamps, SAMPLE_RATE);
if (DAQmxFailed(error)) { break; }
uInt32 onboard_buf_size;
 
error = DAQmxGetBufOutputOnbrdBufSize(pulse_task_handle, &onboard_buf_size);
if (DAQmxFailed(error)) { break; }
if (CALLBACK_COUNT < onboard_buf_size)
{
error = DAQmxSetBufOutputOnbrdBufSize(pulse_task_handle, CALLBACK_COUNT);
}
 
error = DAQmxCfgOutputBuffer(pulse_task_handle, buffer_count);
if (DAQmxFailed(error)) { break; }
error = DAQmxRegisterEveryNSamplesEvent(pulse_task_handle, DAQmx_Val_Transferred_From_Buffer, CALLBACK_COUNT, 0, EveryNCallback, this);
if (DAQmxFailed(error)) { break; }
 
for (size_t i = 0; i < buffer_malloc_count; i++)
{
error = SendCallbackCountData();
 
if (DAQmxFailed(error)) { break; }
}
} while (false);
 
if (DAQmxFailed(error))
{
StopTask();
}

By the way, when I changed DAQmxCreateDOChan to DAQmxCreateAOChan, the task also runs normally. I suspect the onboard buffer size cannot be modified for DO channels.
Could you please help clarify this issue? Thank you very much!
0 Kudos
Message 1 of 3
(222 Views)

By the way change DAQmxSetWriteRegenMode(pulse_task_handle, DAQmx_Val_AllowRegen) to DAQmx_Val_DoNotAllowRegen still meets the same error.

0 Kudos
Message 2 of 3
(220 Views)

I'm using the PCIe-6321 device.

0 Kudos
Message 3 of 3
(202 Views)