Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI Daq Synchronization Problem

I have two X Seriers 6353 Daqs. And I'd like to use both of them at the same time for data acquisition. 

 

My configuration: Dev6 is master and Dev5 is slave. I have Dev6 export the sample clock signal. And the signal is physically connected to Dev5/PFI1 port. I also setup a trigger. The trigger signal is generated from Dev6/port1/line2 and it's physically connected to Dev6/PFI0 and Dev5/PFI0 ports. 

 

When I run the code, I get good results from all the channels on Dev6 and all but one channel on Dev5. The first channel on Dev5 always return bogus values. For example, when acquiring just from the first channel on Dev5 I get 0.1. But when I have it in a master and slave configuration, I always get -2.7. Also, If I change the start channel of Dev5 from ai0 to ai1 I get the same problem on ai1. 

 

Any help is appreciated!

 

The code (I'm using the PyDAQmx package that wrappers around the NI DAQmx ANSI C library). 

 

from PyDAQmx import *
import numpy

taskHandle1 = TaskHandle()
taskHandle2 = TaskHandle()
taskHandle3 = TaskHandle()

duration = 10 # in seconds
sample_rate = 1000 # samples per second
sample_num = duration * sample_rate # total number of samples
chan_num = 16
buffer_size = chan_num*sample_num
read1 = int32()
read2 = int32()
write = int32()
data1 = numpy.zeros((buffer_size,), dtype=numpy.float64)
data2 = numpy.zeros((buffer_size,), dtype=numpy.float64)
data3 = numpy.ones((1,), dtype=numpy.uint8)
data4 = numpy.zeros((1,), dtype=numpy.uint8)

 

# DAQmx Configure Code

#Master
DAQmxCreateTask("",byref(taskHandle1))
DAQmxCreateAIVoltageChan(taskHandle1,"Dev6/ai0:7,Dev6/ai16:23","",DAQmx_Val_Diff,-0.1,0.1,DAQmx_Val_Volts,None)
DAQmxCfgSampClkTiming(taskHandle1,"",float(sample_rate),DAQmx_Val_Rising,DAQmx_Val_ContSamps ,sample_num)

DAQmxCfgDigEdgeStartTrig(taskHandle1, "/Dev6/PFI0", DAQmx_Val_Rising )
DAQmxExportSignal(taskHandle1,DAQmx_Val_SampleClock, "/Dev6/PFI1")

#Slave

DAQmxCreateTask("",byref(taskHandle2))
DAQmxCreateAIVoltageChan(taskHandle2,"Dev5/ai0:7,Dev5/ai16:23","",DAQmx_Val_Diff,-0.1,0.1,DAQmx_Val_Volts,None)
DAQmxCfgSampClkTiming(taskHandle2,"/Dev5/PFI1",float(sample_rate),DAQmx_Val_Rising,DAQmx_Val_ContSamps ,sample_num)
DAQmxCfgDigEdgeStartTrig(taskHandle2, "/Dev5/PFI0", DAQmx_Val_Rising )

 

#Trigger

DAQmxCreateTask("",byref(taskHandle3))

DAQmxCreateDOChan(taskHandle3, "/Dev6/port1/line2", "", DAQmx_Val_ChanPerLine)


#DAQmx Start Code
DAQmxStartTask(taskHandle1)

DAQmxStartTask(taskHandle2)

DAQmxStartTask(taskHandle3)

 

#DAQmx Write Code

#Send Trigger Signal
DAQmxWriteDigitalLines(taskHandle3,1,False,10.0,DAQmx_Val_GroupByChannel,data4,byref(write),None);
DAQmxWriteDigitalLines(taskHandle3,1,False,10.0,DAQmx_Val_GroupByChannel,data3,byref(write),None);


#DAQmx Read Code
DAQmxReadAnalogF64(taskHandle1,sample_num,10.0,DAQmx_Val_GroupByChannel,data1,buffer_size,byref(read1),None)
DAQmxReadAnalogF64(taskHandle2,sample_num,10.0,DAQmx_Val_GroupByChannel,data2,buffer_size,byref(read2),None)

 

print "Acquired %d points\n"%read1.value
print "Acquired %d points\n"%read2.value
print "done"

for x in xrange(chan_num):
print numpy.average(data1[x*sample_num:(x+1)*sample_num-1])*10000

for x in xrange(chan_num):
print numpy.average(data2[x*sample_num:(x+1)*sample_num-1])*10000
numpy.savetxt("dev5ai0.csv", data2[0:sample_num],fmt='%.18e', delimiter=' ', newline='\n')

0 Kudos
Message 1 of 6
(3,654 Views)

I can't edit the original post.

 

I've found that all the readings from the slave device are bogus. If you run the slave device only I get good readings. Any ideas of why the synchronization is not working as expected?

0 Kudos
Message 2 of 6
(3,636 Views)

Hello Kzhou,

 

I noticed that in the section ‘’DAQmx Start Code’’, the master device is started before the slave device. For synchronization, you should arm the slave task before starting the master slave; otherwise you will miss the trigger pulse. Please check the example Continuous AI for reference. You can find it navigating to Start>>All Programs>>National Instruments>>NI-DAQ>>Text-Base Code Support>>ANSI C Examples>>Synchronization>>Multi-Device>>Continuous AI.

 

Best Regards,

 

Alina M 

0 Kudos
Message 3 of 6
(3,619 Views)

I've switched the order of startTask, putting the slaves ahead of the master. But I get the same result. The first channel of the slave devices still give me bogus readings. 

 

I've looked at the example (ContinuousAI.c under Sync/Multi-Device). The devices mentioned don't include USB X-Series Daqs. Does the sync method still apply? 

 

For my code, I've followed the example at http://www.ni.com/white-paper/6829/en. That example specifically demostrates how to sync the USB Daq. I basically convert the labview code into python (based on ANSI C lib). 

0 Kudos
Message 4 of 6
(3,608 Views)

There's no reason for synchronization to have the effect you're seeing.

How do you have your AI channels wired up? I see that you're using differential mode in this program, which means that the AI values you read from DAQmx will be the difference between AI+ and AI- (not between AI+ and AI GND).

0 Kudos
Message 5 of 6
(3,565 Views)

Hello Kzhou,

 

I tried the synchronization using USB-63663 and it worked fine. As Chad mentioned, it is an unusual reading, since you mentioned that using the device alone gives good results, it seems the device works fine. Just to make sure, could you post the pin out wiring you’re using between devices?

 

Best Regards,

 

Alina M

 

0 Kudos
Message 6 of 6
(3,551 Views)