Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Taskhandle restart but not repeated write

Hello, I have a task handle that is already created. And I have a for loop. In this loop, I will start this task, make some comments, and then stop the task. However, when I start the next for loop, the task needs to restart, which should rewrite the signal data. But the signal in every loop is the same, so I want to ask how to avoid rewriting the signal data.

NOTE: in the figures I will run the threeD_lissajous_configure() and then threeD_lissajous_run()

Code:

 

lissajousdata = new float64[total_samples * 2];
NIgenerateSineWave(lissajousdata, total_samples, MEMSamp, xfrequency,0, samplingRate, xoffset, 0);
NIgenerateSineWave(lissajousdata, total_samples, MEMSamp, yfrequency,0, samplingRate, yoffset, 1);
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", samplingRate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, total_samples));


DAQmxErrChk(DAQmxStartTask(taskHandlefilter));
while (running) {
{
std::lock_guard<std::mutex> lock(mtx);
if (!running) break; // Exit if state is false
}
for (int blockorder = 0; blockorder < voltage_set_result.size(); blockorder++) {

if (blockorder == 0) {
zperiod = 0;
}
DAQmxErrChk(DAQmxWriteAnalogF64(taskHandle, total_samples, TRUE, DAQmx_Val_WaitInfinitely, DAQmx_Val_GroupByScanNumber, lissajousdata, NULL, NULL));
DAQmxErrChk(DAQmxWriteDigitalLines(taskHandleTTL, total_samples, TRUE, 10, DAQmx_Val_GroupByScanNumber, ttldata, NULL, NULL));
auto start_time = high_resolution_clock::now();
eCOMCaspErr setfocus_state = Casp_SetFocusVoltage(voltage_set_result[blockorder]);

auto end_time = high_resolution_clock::now();
auto duration_us = duration_cast<microseconds>(end_time - start_time);
zduration_per_change[blockorder] = double(duration_us.count());

zperiod = zperiod + float64(duration_us.count());
if (blockorder == voltage_set_result.size() - 1) {
zfrequency = 1000000 / zperiod;
//std::cout << zfrequency << endl;
if (zDurationCallback && running) {
zDurationCallback(zduration_per_change, frame_order);
}
}
//std::cout << float64(duration_us.count()) << endl;

DAQmxErrChk(DAQmxStopTask(taskHandle));
DAQmxErrChk(DAQmxStopTask(taskHandleTTL));
frame_order++;
}
}
DAQmxErrChk(DAQmxStopTask(taskHandle));
DAQmxErrChk(DAQmxStopTask(taskHandletrigger));
DAQmxErrChk(DAQmxStopTask(taskHandlefilter));
DAQmxErrChk(DAQmxClearTask(taskHandle));
DAQmxErrChk(DAQmxClearTask(taskHandletrigger));
DAQmxErrChk(DAQmxClearTask(taskHandlefilter));
std::cout << "Close NIDAQ: Success" << endl;
eCOMCaspErr closeCOM6_state = Casp_CloseCOM();
const char* closeCOM6_state_messenge = Casp_GetErrorMsg(closeCOM6_state);
std::cout << "Close COM6: " << closeCOM6_state_messenge << endl;

 

Download All
0 Kudos
Message 1 of 1
(62 Views)