Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Update buffer in a Retriggerable task

I am wondering if anyone know how to update the buffer for a retriggerable AO task.

I want to change the the AO buffer before the next trigger. And then I can get the new wavefrom for the next trigger. 

Now the only way I can do is to stop the task. And update the buffer, Then start the task again. But It will take more than 20ms to restart the task. I am wonder if anyone know how to update the buffer without stop the task.

The configuration of the task is as follows:

 

(DAQmxCreateAOVoltageChan(taskHandle_Scanner,"Dev2/ao1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
(DAQmxCfgSampClkTiming(taskHandle_Scanner,"",sample_speed,DAQmx_Val_Falling,DAQmx_Val_FiniteSamps,10));
DAQmxCfgDigEdgeStartTrig (taskHandle_Scanner, "/Dev2/PFI0", DAQmx_Val_Rising ); //X trigger
DAQmxSetStartTrigRetriggerable(taskHandle_Scanner,TRUE);
DAQmxCfgOutputBuffer (taskHandle_Scanner, 10);
float64 datax[10];
for (i=0;i<10;i++)
{
dataxy[i]=m_Scane_Step*(i-5);
}
DAQmxWriteAnalogF64(taskHandle_Scanner,10,0,0,DAQmx_Val_GroupByChannel,dataxy,NULL,NULL);
DAQmxStartTask(taskHandle_Scanner);

0 Kudos
Message 1 of 10
(4,533 Views)

Hi taoxd!

The ability to set your output buffer size is device-specific. Let me know what device you are using and I will check for you to see if reconfiguring the output buffer while the task is running is possible.

Thanks!

Collin D.
Software Product Manager
0 Kudos
Message 2 of 10
(4,485 Views)

Hi Collin,

   We are using PCIE-6363. 

  Tanks!

0 Kudos
Message 3 of 10
(4,478 Views)

Hello taoxd,

 

Thank you for the information. It looks like the only properties for that series of device that can be reconfigured during run-time are buffer size. Is this the property you are interested in changing?

 

If so, it should be as simple as calling the function:

 

int32 __CFUNC DAQmxSetBufOutputBufSize(TaskHandle taskHandle, uInt32 data);

 

However, it seems this is the only property that you are able to set during run-time for your device. If you can try explaining what your end-goal is for your device, I could be of more assistance to you.

Collin D.
Software Product Manager
0 Kudos
Message 4 of 10
(4,475 Views)

Hi Collin,

   This is for a feedback system. We start a retriggerable task to contorl a scaning mirror using AO port. On the same time, the signal from the photo dector is measrued through AI port. Then we calcuate the contorl signal for the scanning mirror using the computer and update the value in AO buffer. So the mirror will steer to an new angle. We use a external trigger for each iteration. So We want to update the value in the AO buffer for each iteration. I had tried to stop and restart the task. That works. But it takes more than 30ms to restart the task. So the ideal case is to update the value in AO buffer and use a external trigger to restart the task.

   Please let me know if you have any good idea for this applicaiton.   

 

 

Best,

Xiaodong

0 Kudos
Message 5 of 10
(4,471 Views)

So for our devices, it looks like the only reconfigurable property during run-time associated with the buffer is size.

However, it doesn't seem like you would need to update the buffer. Why not just write a new value to the AO every time the external trigger is sensed? Has this not worked for you?

Collin D.
Software Product Manager
0 Kudos
Message 6 of 10
(4,453 Views)

I had tried. But most of the time, AO ouput dose not upate at the following trigger. It will updated after the second trigger. Actually the time between the two trigger is around several millisecond. I also try to add Sleep time for 20ms in my program between each trigger event, but I still can not get the updated value at the following trigger.

 

0 Kudos
Message 7 of 10
(4,450 Views)

Hello taoxd,

Could you post the code you are using to acquire data? 

The AO output should update immediately.

Collin D.
Software Product Manager
0 Kudos
Message 8 of 10
(4,433 Views)

Hello Collin,

  Here is a simple code for testing. I setup two tasks. One is AO output. Another one is DO output for generating the trigger. Terminal "/Dev2/PFI0" is connected to "Dev2/port0/line1" for trigger. Two triggers are generated sequentially. Fot the first trigger, the AO output should be 100 samples fromt 0 to 1V. For the second trigger, the AO should be 0V.  But the result after the seond trigger is the same as the frist one. "DAQmxWriteAnalogF64" can not update the data in the buffer. If I use "-1" for the timeout parameter of the DAQmxWriteAnalogF64, the program is just freezed. 

 

// set up the AO task

sample_speed=1000; 
(DAQmxCreateTask("",&taskHandle_Scanner));
(DAQmxCreateAOVoltageChan(taskHandle_Scanner,"Dev2/ao1","",-1.0,1.0,DAQmx_Val_Volts,NULL));
(DAQmxCfgSampClkTiming(taskHandle_Scanner,"",sample_speed,DAQmx_Val_Falling,DAQmx_Val_FiniteSamps,100));
DAQmxCfgDigEdgeStartTrig (taskHandle_Scanner, "/Dev2/PFI0", DAQmx_Val_Rising );
DAQmxSetStartTrigRetriggerable(taskHandle_Scanner,TRUE);
DAQmxCfgOutputBuffer (taskHandle_Scanner, 100);
// initialize the output data (100 samples)
for (i=0;i<100;i++) {Data_AO[i]=0.01*(i);}

DAQmxWriteAnalogF64(taskHandle_Scanner,100,0,-1,DAQmx_Val_GroupByChannel,Data_AO,NULL,NULL);
xx=DAQmxStartTask(taskHandle_Scanner);

 

// Setup the trigger for the AO
(DAQmxCreateTask("",&taskHandle_Scanner_trigger));
DAQmxCreateDOChan (taskHandle_Scanner_trigger,"Dev2/port0/line1","trigger",DAQmx_Val_ChanPerLine );
DAQmxStartTask(taskHandle_Scanner_trigger);

 

// Start the trigger
Data_Trigger[0]=0;
DAQmxWriteDigitalLines(taskHandle_Scanner_trigger,1,1,10.0,DAQmx_Val_GroupByChannel,Data_Trigger,NULL,NULL);
Data_Trigger[0]=1;
DAQmxWriteDigitalLines(taskHandle_Scanner_trigger,1,1,10.0,DAQmx_Val_GroupByChannel ,Data_Trigger,NULL,NULL);

// Wait 2 second for AO output
Sleep(2000);

 

// Update the data for AO
for (i=0;i<100;i++) { Data_AO_New[i]=0; }
xx=DAQmxWriteAnalogF64(taskHandle_Scanner,100,0,0.5,DAQmx_Val_GroupByChannel,Data_AO_New,NULL,NULL);


// Start the trigger again
Data_Trigger[0]=0;
DAQmxWriteDigitalLines(taskHandle_Scanner_trigger,1,1,10.0,DAQmx_Val_GroupByChannel ,Data_Trigger,NULL,NULL);
Data_Trigger[0]=1;
DAQmxWriteDigitalLines(taskHandle_Scanner_trigger,1,1,10.0,DAQmx_Val_GroupByChannel ,Data_Trigger,NULL,NULL);
//Wait 2 second for AO output
Sleep(2000);

0 Kudos
Message 9 of 10
(4,392 Views)

I would suggest taking this approach instead:

 

1.  Configure a finite, retriggerable counter output task.  It will be used as the sample clock for the AO task (so it will output N pulses equal to the number of AO samples you are writing each time).  Trigger this counter task with your external signal.

 

2.  Configure the AO task to be a continuous task.  Configure the task to not allow regeneration (DAQmxSetWriteRegenMode).  Configure no trigger, but use the internal output of the counter from the first task as the sample clock for this AO task.

 

 

Without explicitly disallowing regeneration, DAQmx will by default regenerate the same data repeatedly.  DAQmx may write multiple copies of the buffer to the hardware FIFO in an attempt to prevent an underrun error, and once data is written to the FIFO it cannot be overwritten with new data.

 

One thing to look out for is that if you receive a trigger before you can write new data to the buffer you would receive an error and have to restart the task.

 

 

Best Regards,

John Passiak
0 Kudos
Message 10 of 10
(4,378 Views)