简体   繁体   中英

Error while running program in qt to read from DAQ

I have a simple data acquisition system to read analog dc voltage from the NI USB 6009. I have also created a qt console application to use the NIDAQmxbase functionality.

The .pro file is as follows

QT += core
QT -= gui

TARGET = untitled4
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp
LIBS += "C:\Users\nikhilmurthy161229\Documents\untitled3\nidaqmxbase.lib"
HEADERS += "C:\Users\nikhilmurthy161229\Documents\untitled3\NIDAQmxBase.h"

I have included the .lib file and the .h file in the project folder.

MY main.cpp file looks as follows

#include <QCoreApplication>
#include <stdio.h>
#include <NIDAQmxBase.h>


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

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    // Task parameters
        int32       error = 0;
        TaskHandle  taskHandle = 0;
        char        errBuff[2048]={'\0'};

        // Channel parameters
        char        chan[] = "nikhil\ai0";
        float64     min = 0;
        float64     max = 5;

        // Timing parameters
        uInt64      samplesPerChan = 1;

        // Data read parameters
        float64     data;
        int32       pointsToRead = 1;
        int32       pointsRead;
        float64     timeout = 5;


        DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
        DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
        DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
        DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByChannel,&data,samplesPerChan,&pointsRead,NULL));
        DAQmxErrChk (DAQmxBaseStopTask(taskHandle));
        DAQmxErrChk (DAQmxBaseClearTask(taskHandle));

        printf ("Acquired reading: %f\n", data);

    Error:
        if( DAQmxFailed(error) )
            DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
        if( taskHandle!=0 ) {
            DAQmxBaseStopTask(taskHandle);
            DAQmxBaseClearTask(taskHandle);
        }
        if( DAQmxFailed(error) )
        printf ("DAQmxBase Error %ld: %s\n", error, errBuff);
        return a.exec();
}

However when i run the program I am getting the following error "DAQmxBase Error -200428: Value passed to the Task/channels In contril is invalid"

I have verified that the device name is same as in NI MAX but the problem still persists.

PLEASE HELP

As a quick guess I would make your chan variable

char        chan[] = "nikhil\\ai0";

The char array is probably interpreting the backslash

The DAQ device name is incorrect.

Even though you used MAX to rename the device to nikhil , DAQmx Base enumerates devices differently. Use the lsdaq utility to find your device name (likely Dev1 ) and change your chan variable to use the discovered name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM