Discussion:
real time output with varying buffers without delay using PCI-6534 and NIDAQmx
(too old to reply)
sunuk
2008-02-10 12:10:05 UTC
Permalink
Hello. I am currently using PCI-6534 and NIDAQmx to contol piezo scanner.
The piezo scanner hase three axsis and interfaces with PCI-6534 card using 16bit digital form.
My question is how to alleviate the delay when continously outputting diffent buffers.
When I output varying buffer continously, there is about 25ms delay.
To show this, I generate same output buffer(4032 number,sine curve), output that buffer and input corresponding piezo scanner output in a while loop.
See attached figure and source code.
Is there anybody to know this problem and solution?
 
int _tmain(int argc, _TCHAR* argv[]){     int32       error=0;    TaskHandle  taskHandle=0;        TaskHandle  taskHandle1=0;     TaskHandle  taskHandle2=0;     TaskHandle  InputTaskHandle=0;
    uInt32      numChannels;     bool32      done=0;    char        errBuff[2048]={'\0'};    char        ch;    int32  sampsRead,totalRead=0;
     int outputBufferSize = num_point*6;    signed short *outputBuffer = new signed short[outputBufferSize];    signed short *inputBuffer = new signed short[outputBufferSize];   
    //For real time position data output and input    //Firstly setting input port for continuous data input    DAQmxErrChk (Configure_ReadDigPortExtClk("Dev1/port2:3","/Dev1/PFI3",outputBufferSize+100000000,&InputTaskHandle, &numChannels, outputBufferSize+100000000));    DAQmxErrChk (Start_DigPortExtClk(InputTaskHandle));         //In while loop, position data can be out and in.    while(1){                //When key in 's', then stop scanning         if(kbhit()){            char ch = getch();            if(ch=='s'){                printf("Stop scanning\n");                break;            }        }        //real-time output buffer generation and send data to the NPoint controller.        generate_buffer(outputBuffer);        DAQmxErrChk (Configure_WriteDigPortExtClk("Dev1/port0:1","/Dev1/PFI2",outputBufferSize,&taskHandle1, &numChannels, outputBufferSize));        DAQmxErrChk (Write_DigPortExtClk(taskHandle1,(uInt16*)outputBuffer,outputBufferSize));        DAQmxErrChk (Start_DigPortExtClk(taskHandle1));        DAQmxErrChk (Wait_DigPortExtClk(taskHandle1));        /////////////////////////////////////////////////////////////////////////////                     //Continuous position data input        DAQmxErrChk (Read_Cont_DigPortExtClk(InputTaskHandle, (uInt16*)inputBuffer, outputBufferSize, &sampsRead));               if( s
sunuk
2008-02-22 11:10:10 UTC
Permalink
Hello. These are the user defined functions used in my program.
There is some misunderstating for my question.
My program is about outputing position data that varies real time by user command.
I think that continous generation example you suggested is not proper for my application if there are no functions related to fast regeneration of buffer.
If you know about this, please describe it in detail of how to use using mx functions.
 
By the way, as you mentioned, Configure_WriteDigPortExtClk, Write_DigPortExtClk, Start_DigPortExtClk and Wait_DigPortExtClk functions in the while loop  makes noticeable delay. But if move port setup function out of the while loop and place the write, start and wait functions inside, some error messages is occured when writing new buffer on the card.  The error message is as follows. How can i solve this?
 
DAQmx Error: Measurements: Attempted to write a sample beyond the final sample generated. The generation has stopped, therefore the sample specified by the combination of position and offset will never be available.
Specify a position and offset which selects a sample up to, but not beyond, thefinal sample generated. The final sample generated can be determined by querying the total samples generated after a generation has stopped.Attempted to Write Sample: 2496
Property: DAQmx_Write_RelativeToCorresponding Value: DAQmx_Val_CurrWritePos
Property: DAQmx_Write_OffsetCorresponding Value:
Task Name: _unnamedTask<2>
Status Code: -200288
 
int32 Configure_WriteDigPortExtClk(const char chan[], const char clockSource[], float64 rate, TaskHandle *taskHandle, uInt32 *numChannels, uInt32 sampsPerChan){     int32 error=0;       /*********************************************************************    *    1. Create a task.    *    2. Create a Digital Output Channel.    *    3. Call the DAQmxCfgSampClkTiming function which sets the sample    *       clock rate. Additionally, set the sample mode to Finite.    *********************************************************************/    DAQmxErrChk (DAQmxCreateTask("",taskHandle));    DAQmxErrChk (DAQmxCreateDOChan(*taskHandle,chan,"",DAQmx_Val_ChanForAllLines));    DAQmxErrChk (DAQmxCfgSampClkTiming(*taskHandle,clockSource,rate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,sampsPerChan));    DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(*taskHandle, "/Dev1/PFI6",DAQmx_Val_Falling));    //DAQmxSetTrigAttribute (*taskHandle, DAQmx_StartTrig_Retriggerable, TRUE);        if( numChannels )        DAQmxErrChk (DAQmxGetTaskAttribute(*taskHandle,DAQmx_Task_NumChans,numChannels));
Error:    return error;}
int32 Configure_ReadDigPortExtClk(const char chan[], const char clockSource[], float64 rate, TaskHandle *taskHandle, uInt32 *numChannels, uInt32 sampsPerChan){     int32 error=0;
    /*********************************************************************    *    1. Create a task.    *    2. Create a Digital Input Channel.    *    3. Call the DAQmxCfgSampClkTiming function which sets the sample    *       clock rate. Additionally, set the sample mode to Finite.    *********************************************************************/    DAQmxErrChk (DAQmxCreateTask("",taskHandle));    DAQmxErrChk (DAQmxCreateDIChan(*taskHandle,chan,"",DAQmx_Val_ChanForAllLines)); 
J_Thomas
2008-02-25 23:10:08 UTC
Permalink
Hi sunuk, Error 200288 often results from analog output operations that have been
set up for software re-triggering. In Traditional NI-DAQ, you only need
to call the start command to re-enable the trigger. In NI-DAQmx, you must call DAQmx Stop Task after a read (analog input) or write (analog output) operation before re-enabling the triggers. As in Traditional NI-DAQ, the start (DAQmx Start Task) command re-enables the trigger.The only other reference I found to error -200288 when writing to the PCI-6534 was the following discussion forum post:<a href="message?board.id=70&amp;message.id=3990&amp;requireLogin=False" target="_blank">
PXI-6534 rewriting IO buffer with DAQmx causes error -200288</a> Hope this helps.
sunuk
2008-02-26 11:10:10 UTC
Permalink
Really good!. This is what I want to find out.
Thanks.

Loading...