LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

acquire signals with NIDaqMx

Hi all, I have a problem about the acquisition of signals using CVI and NIDaqMx libraries.
I would like to create a DLL in order to use it in LabView RT Module to acquire data as doubles.
I've already written some lines of code, but I think something is wrong or missing. In fact when I run it, I always acquire a strange value  (2e17), surely wrong.
I add the code below... Can you help me?

    / Include files
    #include "acquisizione.h"
    #include <cvirte.h>
    #include <userint.h>
    #include <ansi_c.h>
    #include <NIDAQmx.h>


    TaskHandle input=-1;
    float64 datain [10000];

    // GLOBAL FUNCTIONS

void init_acq(int samples_in)
{
     // TASK
     DAQmxCreateTask(TASK_NAME,&input);
     DAQmxAddGlobalChansToTask (input, "Voltage"); // Da mettere quì o dopo??
     // CHANNEL
     DAQmxCreateAIVoltageChan (input, "Dev1/ai0", "Voltage", DAQmx_Val_Cfg_Default, -10, 12,
                         DAQmx_Val_Volts,"NULL");
     // Attributes
     DAQmxSetChanAttribute (input, "Voltage", DAQmx_AI_Voltage_Units, DAQmx_Val_Volts, datain);
         
     // TIMING
     DAQmxCfgSampClkTiming (input, "/Dev1/ai/SampleClock", samples_in, DAQmx_Val_Rising,
                       DAQmx_Val_FiniteSamps, samples_in);
     DAQmxSetTimingAttribute (input, DAQmx_SampQuant_SampMode, DAQmx_Val_FiniteSamps);
     DAQmxSetTimingAttribute (input, DAQmx_SampTimingType, DAQmx_Val_SampClk);
     // READ
     DAQmxReadAnalogF64 (input, DAQmx_Val_Auto, 10.0, DAQmx_Val_GroupByChannel, datain, samples_in, 0,
                    0);
     DAQmxSetReadAttribute (input, DAQmx_Read_RelativeTo, DAQmx_Val_CurrReadPos);
     DAQmxSetReadAttribute (input, DAQmx_Read_ChannelsToRead, "Voltage");
     DAQmxSetReadAttribute (input, DAQmx_Read_OverWrite, DAQmx_Val_DoNotOverwriteUnreadSamps);
 }
float64 read_acq(int i)
{
    return datain[i-1];
}
void start_acq (void)
{
    DAQmxStartTask (input);
}   
void stop_acq (void)
{
    DAQmxStopTask(input);
}
void clear_acq (void)
{
    DAQmxClearTask (input);
}


Thanks for the future answers.

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

Hi Elena,

what I can suggest is to take a look at CVI example for analog measurements that works fine and start from there to program your application.

You can find the examples by clicking on the Help tab and then "Find Examples". Look in "Hardware Input and Output->Analog Measurements-> Voltage-> Acq-IntClk.prj".

Hope this can help,

Andrea N.
Principal Applications Engineer - Semiconductor EMEA
National Instruments Italy
Certified LabVIEW Architect - Certified TestStand Architect
0 Kudos
Message 2 of 3
(3,200 Views)
Hello Elenaaa,

it is good practice to use error checking in a program. You might be receiving a DAQ error from one or more DAQ functions without knowing it.

I would recommend to use error checking (there are some predefined macros in the DAQmx header file and in examples).

Hope this helps.
LDP
0 Kudos
Message 3 of 3
(3,197 Views)