Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxBaseReadAnalogF64 on Linux returning no samples

Hello,

 

I am trying to solve a mystery. I have a PCI 6220 board installed in a linux PC running OpenSUSE 12.2. When I compile and run my test program and try to read in samples the DAQmxBaseReadAnalogF64 returns 0 for success but a samplecount of 0.

 

If I install the card in a Windows 7 PC using DAQmx (nor base) everything runs perfectly and I get samples as expected.

 

I also tried the NI example programs, but these also return no samples.

 

My assumption was NI drivers, so I tried to uninstall and reinstall the drivers, rebooted and then tried again -  Same result.

 

Have I missed something obvious or any suggestions?

 

The basic source code as follows:

 

bool
do_initialise()
        {
        XString        s;

        m_nchannels = 16;
        m_device = "Dev1";
        m_maxSampleValue = 10.0;
        m_sampleRate = 8000;
        m_samplesPerCallback = m_sampleRate / 10;
        m_dataBufSize = m_nchannels * m_samplesPerCallback;

        float64        *pFloatBuf=new float64[m_dataBufSize];
        m_databuf = pFloatBuf;

        return true;
        }

bool
do_open()
        {
        m_openflag = false;

        x_int32_t    r=0;

        r = DAQmxBaseCreateTask("", (TaskHandle *)&m_handle);
        if (r >= 0)
            {
            for (int i=0;i<m_nchannels;i++)
                {
                XString        channelname;

                channelname.format("%s/ai%d", m_device.c_str(), i);

                r = DAQmxBaseCreateAIVoltageChan((TaskHandle)m_handle,
                                            channelname,
                                            "",
                                            DAQmx_Val_RSE,
                                            -m_maxSampleValue,
                                            m_maxSampleValue,
                                            DAQmx_Val_Volts,
                                            NULL);
                
                if (r < 0)
                    {
                    // log error
                    }
                }
            }
        else
            {
            // log error
            }

        if (r >= 0)
            {
            // Our output blocks are in 1/10th second
            // Out input frequency is fixed at 8000Hz
            // So request 800 samples!
            r = DAQmxBaseCfgSampClkTiming((TaskHandle)m_handle, "", 8000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, m_samplesPerCallback * m_nchannels * 10);

            if (r < 0)
                {
                // log error
                }
            }

        if (r >= 0)
            {
            r = DAQmxBaseStartTask((TaskHandle)m_handle);
            if (r < 0)
                {
                // log error
                }
            }

        if (r >= 0)
            {
            m_openflag = true;
            }
        else
            {
            DAQmxBaseStopTask((TaskHandle)m_handle);
            DAQmxBaseClearTask((TaskHandle)m_handle);
            }
        
        return m_openflag;
        }


bool
do_close()
        {
        DAQmxBaseStopTask((TaskHandle)m_handle);
        DAQmxBaseClearTask((TaskHandle)m_handle);

 

        m_openflag = false;

        return true;
        }


bool
do_onDataReady()
        {
        float64    *data=(float64 *)m_databuf;
        int32    samplesread=0;
        int        r;

        r = DAQmxBaseReadAnalogF64((TaskHandle)m_handle, m_samplesPerCallback, 10.0, DAQmx_Val_GroupByChannel, data, m_dataBufSize, &samplesread, NULL);

        theAppLog.debug("After DAQmxReadAnalogF64 r=%d, samplesread=%d", r, samplesread);
        
        return true;
        }


int
main()
        {
        bool    ok=true;

        if (ok) ok = do_initialise();
        if (ok) ok = do_open();

        for (int i=0;ok&&i<100;i++)
            {
            ok = do_onDataReady();
            }

        if (ok) ok = do_close();
        do_shutdown();
        }

0 Kudos
Message 1 of 2
(3,821 Views)

Hi Simon,

Have you seen these papers on working with DAQmx in Linux?

"Programming Data Acquisition for Linux with NI-DAQmx Base"
http://www.ni.com/tutorial/3838/en/

"NI-DAQmx for Linux Frequently Asked Questions"
http://www.ni.com/product-documentation/3695/en/#toc7

Regards

Art
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(3,767 Views)