Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Equivalent of Analog 2D Nchan Nsamps in pyDAQmx

Solved!
Go to solution

Hi,

 

I have a Labview VI that uses "Analog 2D I16 Nchan Nsamps" DAQ function to acquire continously samples with an external sample clock and an external trigger.

 

I want to do this in python (using pyDAQmx).

 

I tried, configuring the timing and AIchannel just like in labview, but with AnalogReadF64 only it gives "ADC conversion attempted before the prior conversion was complete".

 

I've seen the ANSI C example "ContAcq-ExtClk-DigStart.c" that uses "RegisterEveryNSamplesEvent", but I want to be sure that I have to use it.

 

--> What is the equivalent of "Analog 2D I16 Nchan Nsamps" in pyDAQmx ? Is that with "RegisterEveryNSamplesEvent" or not ?

 

Many thanks,

0 Kudos
Message 1 of 7
(3,807 Views)

Hi mp_INRS_1650,

 

You're on the right track.  Overall, it looks like the DAQmxReadAnalogF64 is the pyDAQmx function with analogous functionality to a multiple channel, multiple sample read.  I'm not sure exactly how pyDAQmx goes about buffered (multi-sample) acquisition, but this example from their site shows the basic architecture of a multiple channel acquisition:

https://pythonhosted.org/PyDAQmx/examples/multi_channel_analog_input.html

 

 

 

Matt | NI Systems Engineering
0 Kudos
Message 2 of 7
(3,783 Views)

Hi,

 

Thank you so much for your response.

 

So ReadAnalogF64 seems to be the equivalent ?

 

I've also seen the example of multichannel Analog Input Output in pyDAQmx

 

But even if I do have 2 channels, I am trying to make, for now, one channel work (1 channel, N sample).

 

But I have this error "ADC conversion attempted before the prior conversion was complete", which indicates that the query of the data in the buffer is going too fast, isn't it ?

 

Seems strange since I've just copied what my labview VI does...

 

 

0 Kudos
Message 3 of 7
(3,779 Views)

The one/multiple channels is a hardware limitation.  If you can make the measurement work with one analog input channel, awesome.  If you have two sensors/daq devices you'll definitely have to use multiple channels in software to fully interpret the measurement.

 

That buffer error is interesting; it sounds like your buffer probably just isn't large enough, but it could also be that it is adequately sized and being queried too quickly.  I would look into increasing your buffer size and see what happens.  What is your sampling rate and current buffer size?  

Matt | NI Systems Engineering
0 Kudos
Message 4 of 7
(3,762 Views)

Hello Matt

 

My rate is 4e6, my buffer_size also. But increasing the buffer size does not solve the problem.

 

I've tried with RegisterEvery Nsamples, but it raises errors, especially because "DAQmx_Val_Acquired_Into_Buffer" stays at '1' I suppose.

 

Also, I'm not totally copying what the Labview code does : it sets the "Start.Delay" in DAQmx trigger to 5e-6 seconds (with an external AD clock), but when I try to do the same in my code I get the error : "Trigger delay is not available using an external AD clock". Why Labview can do it while I can't ?

 

Max

 

 

0 Kudos
Message 5 of 7
(3,740 Views)

Could you look into using any of the examples in C that ship with LabVIEW?  I can verify the functionality of those since they are actually written here at NI, but no problem if you are committed to coding in Python.  As far as I can tell, PyDAQmx essentially enables you to call into the C .dlls using Python syntax.  Can you get any of the other examples on the PyDAQmx site to run (e.g. Analog or Digital Output)?  

 

Because this is a third-party add-on, it is not directly supported here and I can't speak to the uses of different functions in PyDAQmx.  Give the other examples they provide a try and hopefully that will add to your understanding of how the functions work and interface with the ANSI C code that ships with NI software products.  

Matt | NI Systems Engineering
0 Kudos
Message 6 of 7
(3,716 Views)
Solution
Accepted by topic author mp_INRS_1650

Hello Matt,

 

I indeed inspired a lot from C examples.

 

I've just found out that I MUST NOT use "DAQmxCfgSampClkTiming" function, but rather set each properties separately : 

using "DAQmxSetSampTimingType" for instance, etc.

 

And it worked.

 

So the answer of my original question : yes, ReadAnalogF64 can do the job of "Analog 2D I16 Nchan Nsamps"

 

Thank you very much for your help !

0 Kudos
Message 7 of 7
(3,714 Views)