Quantcast
Channel: Digital I/O topics
Viewing all articles
Browse latest Browse all 2182

read AI and DI simultaneously

$
0
0
Hello,
I want to read AI and DI simultaneously(of course there should be some gap during sampling time and read time?)
I'm using USB-6361, NIMAX 19.6, python 3.7.6, windows 10.
I don't mind if you give me any idea not only for python but also any other text based method.
I wanna read 2 channels of AI (1MS/s/ch) and 2 channels of DI all together.
 
I used function generator to make sine wave(3.2V amplitude, 1kHz) and connected it to ai0. And connected sync to PFI0.
 
If I set timeout of ReadDigitalLines to 0, it seems it lost a lot of DI data (or maybe clock freq. is too high? I'm not sure of it. Actually I couldn't found any information about how DI works.) Like the plot below. (orange line is DI. I drew only 1 AI chan and 1 DI chan.)
Figure 1 2020-05-06 오후 6_22_21.png

If I set timeout of ReadDigitalLines to -1, it seems it reads DI data too much. (or maybe clock freq. is too low? Again, I'm not sure of it.) Like the plot below. It also breaks after it reads data only once.
Figure 1 2020-05-06 오후 6_22_03.png
And this is zoom-in plot.
Figure 1 2020-05-06 오후 6_21_46.png
Please let me know if somebody has any idea.
My code is as below.
 
nidaq.DAQmxCreateAIVoltageChan(AItaskHandle,b"Dev%d/ai0,Dev%d/ai2" %(num,num),"",DAQmx_Val_Diff,float64(-5.0),float64(5.0),DAQmx_Val_Volts,None)
nidaq.DAQmxCreateDIChan(DItaskHandle,b"Dev%d/PFI0,Dev%d/PFI1" %(num,num),"",DAQmx_Val_ChanPerLine)
nidaq.DAQmxCfgSampClkTiming(AItaskHandle,"",float64(sampleRate),DAQmx_Val_Rising,DAQmx_Val_ContSamps,uInt64(1000000))
 
nidaq.DAQmxStartTask( DItaskHandle )
nidaq.DAQmxStartTask( AItaskHandle )
 
while True:
  readAI = uInt32()
  readDI = uInt32()
  bytesPerSamps = uInt32()
    nidaq.DAQmxReadAnalogF64(AItaskHandle,samples_per_chan,float64(-1),DAQmx_Val_GroupByScanNumber,AIdata.ctypes.data,Length,ctypes.byref(readAI),None)
nidaq.DAQmxReadDigitalLines(DItaskHandle,samples_per_chan,float64(0),DAQmx_Val_GroupByScanNumber,DIdata.ctypes.data,Length,ctypes.byref(readDI),ctypes.byref(bytesPerSamps),None)
 
 
Someone suggested me to set sample clock for DI like this: nidaq.DAQmxCfgSampClkTiming(DItaskHandle,"Dev%d/ai/SampleClock" %num,float64(sampleRate),DAQmx_Val_Rising,DAQmx_Val_ContSamps,uInt64(1000000))
But it doesn't read DI in this case. (I heard that it works for M series PCI board. Mine is X series, USB.)
 
Thank you in advance!
 

Viewing all articles
Browse latest Browse all 2182

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>