Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6251 , DAQmx Analog Output, ao0, ao1, error utilizing both ports

HI,

 

I'm having an issue creating two analog interfaces. I keep receiving an error when I try to address a range "Dev1/ao0:1". I can address "Dev1/ao0" and create an nice sinusoid. The issue is I want to utilize both an0 and an1 analog interfaces to output signals. I'm developing in C++. Any ideas why I can not address both analog outputs? I have tried to use ao1 and the port works just fine. 

 

Code:

 

#include <QtGui/QApplication>
#include "mainwindow.h"
#include "ni_usb_6361.h"
#include "math.h"
#include <QDebug>

#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }

#define PI	3.1415926535

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

        int         error=0;
        TaskHandle  taskHandle=0, taskHandle2=0;
        float64     data[4000], data2[36000];
        char        errBuff[2048]={'\0'};
        int			i=0;
        int32   	written;
        int32       read;

        for(i=0;i<4000;i++)
            data[i] = 1*sin(2*PI*100*i/1000);


        /*********************************************/
        /*/ DAQmx Configure Code
        /*********************************************/
        DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
        DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0:1","",-5.0,5.0,DAQmx_Val_Volts,NULL));
        DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,4000));


        DAQmxErrChk (DAQmxCreateTask("",&taskHandle2));
        DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle2,"Dev1/ai0","",DAQmx_Val_Diff,-5.0,5.0,DAQmx_Val_Volts,NULL));
        DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle2,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,4000));

        /*********************************************/
        /*/ DAQmx Write Code
        /*********************************************/
        DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,4000,0,10.0,DAQmx_Val_GroupByChannel,data,&written,NULL));

        /*********************************************/
        /*/ DAQmx Start Code
        /*********************************************/
        DAQmxErrChk (DAQmxStartTask(taskHandle));
        DAQmxErrChk (DAQmxStartTask(taskHandle2));

        /*********************************************/
        /*/ DAQmx Wait Code
        /*********************************************/
        DAQmxErrChk (DAQmxReadAnalogF64(taskHandle2,4000,10.0,DAQmx_Val_GroupByChannel,data2,36000,&read,NULL));

        DAQmxErrChk (DAQmxWaitUntilTaskDone(taskHandle,10.0));

        qDebug("Acquired %d points\n",read);
        qDebug()<<data2[0];

    Error:
        if( DAQmxFailed(error) )
            DAQmxGetExtendedErrorInfo(errBuff,2048);
        if( taskHandle!=0 ) {
            /*********************************************/
            /*/ DAQmx Stop Code
            /*********************************************/
            DAQmxStopTask(taskHandle);
            DAQmxClearTask(taskHandle);
        }
        if( taskHandle2!=0 ) {
            /*********************************************/
            /*/ DAQmx Stop Code
            /*********************************************/
            DAQmxStopTask(taskHandle2);
            DAQmxClearTask(taskHandle2);
        }
        if( DAQmxFailed(error) )
            qDebug("DAQmx Error: %s\n",errBuff);
        qDebug("End of program, press Enter key to quit\n");


    return a.exec();
}

 

Thank you

 

0 Kudos
Message 1 of 3
(3,038 Views)

Hi DSTEG,

 

Can you post the error that you're getting?

 

Regards,

 

Carmen C.

Application Engineer

National Instruments

0 Kudos
Message 2 of 3
(3,006 Views)

I figured out the issue. The issue was with:

 

DAQmxWriteAnalogF64(Analog0,4000,0,10.0,DAQmx_Val_GroupByChannel,data,&written,NULL);

 

It was unclear that the output write is per channel. If we are using two channels then the output write samples must be half of the total buffer.  I had to change the write to:

 

 

 

DAQmxWriteAnalogF64(Analog0,2000,0,10.0,DAQmx_Val_GroupByChannel,data,&written,NULL);

 

and then it worked. 

 

Thank you.

 

 

 

0 Kudos
Message 3 of 3
(3,001 Views)