Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI 6361 Linux

Hello

 

I am trying to get a real-time read out of 2 analogue channels on a NI 6361 using Linux, with a sample rate of 500KHz.

I have successfully installed the Linux DAQmx drivers.

 

I have the following C++ driver calls (simplified and excuse any typos I have typed it manually from dev PC):

 

- DAQmxResetDevice("Dev1") // reset settings on device to start clean

- DAQmxCreateTask("task", taskhandle) // create task

- DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "0", DAQmx_Val_Diff, -10.0, 10.0, DAQmx_Val_Volts, NULL) // create channel 0

- DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai1", "0", DAQmx_Val_Diff, -10.0, 10.0, DAQmx_Val_Volts, NULL) // create channel 1

- DAQmxSetSampTimingType(taskHandle, DAQmx_Val_SampClk) // sample using onboard sample clock

- DAQmxSetSampClkRate(taskHandle, 2000000) // onboard clock rate to 2MHz

- DAQmxCfgSampClkTiming(taskHandle, NULL, 500000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 5000) // 500KHz SR, 5k buffer (I have tried buffer sizes all the way from 100 samples to a full 50K read)

- DAQmxStartTask(taskHandle) // start the task

 

This fails with the following error:

DAQmx Error: A hardware failure has occurred. The operation could not be completed as specified.

Status code: -50152

 

The only way I can get it to work, is to add the following call (for both channels):

DAQSetAIDataXferMech(taskHandle, "dev/ai0", DAQmx_Val_ProgrammedIO). However, I can only get up to 250KHz before getting the following error:

DAQmx Error: Onboard device memory overflow. Because of system and/or bus-bandwidth limitations, the driver could not read data from the device fast enough to keep up with the device throughput. Reduce your sample rate. If your data transfer method is interrupts, try using DMA or USB Bulk. Status code: -2000361.

 

Trying to set DMA (e.g. changing DAQmx_Val_ProgrammedIO to DAQmx_Val_DMA) gives me the same error above when I try to start the task:

DAQmx Error: A hardware failure has occurred. The operation could not be completed as specified.

Status code: -50152

 

I have also tried setting up a read call back using DAQmxRegisterEveryNSamplesEvent, but that gives me the same error. The same also happens when I try to set the input buffer sizes (using DAQmxCfgInputBuffer).

 

I've also tried lower sample rates, removing some of the calls (sample clock rate stuff), only using 1 channel, and I am running out of things to try.

 

Is there anything else I need to add in order to change the transfer type to DMA?

Why do I need to force it to ProgrammedIO to get it to work at all?

Do I need to do something different to use the callback functionality?

Or does my board have some fault?

 

Many thanks

Matt

0 Kudos
Message 1 of 10
(3,040 Views)

To add to this, I have checked that DAQmxGetAIDataXferMech confirms that DMA mode is set.

DAQmxGetDevNumDMAChans returns 8.

 

Any ideas?

 

Thanks.

0 Kudos
Message 2 of 10
(2,969 Views)

First, are you using the PXIe-6361 or the USB-6361? The DAQmx readme for Linux, https://download.ni.com/ni-linux-desktop/2021/Q2/readme/drivers/readme_NI-DAQmx , shows that the USB version is not supported on Linux, only the PXIe version.

 

If you are using the PXIe-6361 than what Linux distro are you using?

Message 3 of 10
(2,931 Views)

Hi

 

Thank you for your reply.

I have the PCIe-6361.

 

I am trying to use Debian 11, I installed the Ubuntu 20.04 drivers which are compatible with kernel version 5.x.

They installed OK anyway, I can try using a different distro (either Ubuntu or Centos) if you think that may be the problem, however I have received some (limited) feedback from NI that the issue is with the software I have posted above, but no concrete answer as to what actually is wrong.

 

Thanks for your help.

0 Kudos
Message 4 of 10
(2,928 Views)

I've attached the C program that works on my system. I'm running Linux Mint 20.1 with kernel 5.8.0. This code is adapted from NI's DAQmx C examples. The makefile is included.

 

Message 5 of 10
(2,897 Views)

Thank you for the example.

 

I have compiled and run it on my system and get the following error:

 

DAQmx Error: A hardware failure has occurred. The operation could not be completed as specified.

Task Name: _unnamedTask<0>

Status Code: -50152

End of program, press Enter key to quit

 

This is the same error I am getting in my software.

 

If I add in the following line, it works:

DAQSetAIDataXferMech(taskHandle, "Dev1/ai0", DAQmx_Val_ProgrammedIO)

 

So, this is the same problem from my initial post. For some reason, DMA does not work either on my system or on the board I have. ProgrammedIO is not capable of keeping up with the sample rates we wish to use, so while it works fine for low sample rates (as in your example), it will not work for our use case.

 

Debian 11 uses kernel 5.10, so there is a slight mismatch. I would expect an error during either installation or module load if there was a problem, and it seems weird that only DMA would not work, but I will downgrade the kernel or try a different OS with a 5.8 kernel.

 

Just out of interest, where are the NI C examples? I am struggling to find them anywhere.

 

Thanks for your help.

0 Kudos
Message 6 of 10
(2,887 Views)

I ran my code again with a sample rate at 1000000 S/s and collecting 1000000 samples. It worked fine. Have you tried running a self-test on the PCIe-6361? You can run a self-test with nidaqmxconfig according to the link below:

 

https://www.ni.com/en-us/support/documentation/supplemental/18/daqmx-for-desktop-linux-tools.html 

 

I've been running my examples on a PXIe-6361 so my hardware isn't too different from yours. Maybe your card is bad? I had to have my PXIe-6361 repaired over the summer.

 

I tried looking for the DAQmx C examples online and it looks like that download link disappeared. It was always kind of hard to find. I finally found the zip file on my computer and attached it.

Message 7 of 10
(2,869 Views)

Thanks for the examples, they are very useful.

 

I tried installing CentOS 8 on another machine and ran your example and my software, and they both work.

So, the issue must be the drivers on Debian 11 / kernel 5.10, or they didn't install correctly.

Running the self-test on both machines nidaqmxconfig returns success.

 

I can use CentOS for now, and will have to wait for a driver update for the newer kernel I guess before moving back to Debian 11.

 

Thank you for all your help!

0 Kudos
Message 8 of 10
(2,851 Views)

It's now a year later and I'm having the same exact issue on Ubuntu 22.04 kernel 5.15.0

 

I'm using a pcie-6341 on the above OS, same symptoms as you had: in ni-hwcfg-utility "reset" and "self-test" work, but I get error -50152 when trying "self-calibration" or any dma transfer.

 

One more data point that you guys didn't mention: I ran windows on this machine and the card worked, and the C examples worked.  So I know it's not the card.

 

 

Thought I'd describe my situation here here, and ask if you kids had any success with this.  Have you got your card working?

 

 

0 Kudos
Message 9 of 10
(1,793 Views)

Hi

 

The only way we could get it to work in the end was to downgrade the kernel to version 5.8. We could not get the stock Debian11 5.10 kernel to work.

 

System has been running stable for many months now running Deb11 with the downgraded kernel. Bit of a pain, but perhaps downgrade the kernel on your Ubuntu to 5.8?

 

I think basically the drivers (or at least the DMA specific bits in the drivers) don't work on kernels > 5.8.

0 Kudos
Message 10 of 10
(1,696 Views)