Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

python nidaqmx link ao trigger source to ai

Hello,

 

I am trying to control the ao and ai channels simultaneously. the ao device is NI9264 controlled by PC using  NI cDAQ 9174. and the ai device is NI USB 6212. the following is the codes in python using nidaqmx. when runing this codes, the error occurs as :

nidaqmx.errors.DaqError: Device not available for routing. It is possible that the device needs to be reset or that the device is being reset.
If you are resetting the device, wait for the reset to complete.
For example, if you have used the device through Traditional NI-DAQ, you must reset the device before the requested route can be made. For SCXI devices, you must reset the communicator DAQ device. Call the Traditional NI-DAQ Device Reset VI or the Init_DA_Brds function. To reset all devices in Traditional NI-DAQ, right-click the Traditional NI-DAQ Devices folder in MAX and select Reset Driver for Traditional NI-DAQ.
Task Name: _unnamedTask<2>
Status Code: -89130

 

AND when I try to set trigger source of ai instead, the error shows the source is not valid.

Can anyone please help??

readTask.triggers.start_trigger.cfg_dig_edge_start_trig(trigger_source='/cDAQ1Mod1/ao/StartTrigger')
import nidaqmx
import numpy as np
import time
from nidaqmx import constants
from nidaqmx.stream_readers import AnalogMultiChannelReader
from nidaqmx.stream_writers import AnalogMultiChannelWriter
from nidaqmx.stream_readers import AnalogSingleChannelReader

outputX=np.linspace(10,-10,25000)
outputY=np.linspace(10,-10,25000)


outputData = np.append(outputX,outputY)
outputData=np.append(outputData,outputY)

inputData=np.zeros(25000)
outputData = outputData.reshape((3,len(outputX)))
#outputData = np.transpose(outputData)
print(outputData.shape)
t1=nidaqmx.Task()
#ao_chan_x=t1.ao_channels.add_ao_voltage_chan("cDAQ1Mod1/ao0")
#ao_chan_y=t1.ao_channels.add_ao_voltage_chan("cDAQ1Mod1/ao1")
#outputChannels = ao_chan_x + "," + ao_chan_y


writingrate1=25000
e2=2500
while True:
with nidaqmx.Task() as writeTask, nidaqmx.Task() as readTask:
writeTask.ao_channels.add_ao_voltage_chan('cDAQ1Mod1/ao0:2')
readTask.ai_channels.add_ai_voltage_chan('Dev1/ai0')




writeTask.timing.cfg_samp_clk_timing(rate=writingrate1,
sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,#dont use continuous
samps_per_chan=inputData.size)

readTask.timing.cfg_samp_clk_timing(rate=writingrate1,
source='/cDAQ1Mod1/ao/SampleClock',
sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,
samps_per_chan=len(outputX))
readTask.triggers.start_trigger.cfg_dig_edge_start_trig(trigger_source='/cDAQ1Mod1/ao/StartTrigger') # Setting the trigger on the analog input


reader = AnalogSingleChannelReader(readTask.in_stream)
writer = AnalogMultiChannelWriter(writeTask.out_stream,auto_start=True)

print("The channels linked to WriteTask are: ")
for i in writeTask.ao_channels:
print(i)

print("Starting writing and reading using", outputX.size, "and", inputData.size)
estT = outputX.size / writingrate1
print("Estimated time: ", estT)


writer.write_many_sample(outputData)


print("Start reading/writing")
reader.read_many_sample(inputData)

writeTask.wait_until_done(timeout=estT)
readTask.wait_until_done(timeout=estT + 10)
print("Done with data")





 

0 Kudos
Message 1 of 4
(3,306 Views)

I see that you are trying to route a signal between two different devices. Since they are two separate devices, you have to route a physical signal between them. Do you have a NI 9401 or NI 9402 module on your cDAQ 9174 to use as PFI lines? You have to set up a physical connection between the PFIs on your cDAQ 9174 to the USB 6212.

 

The error is trying to tell you that USB 6212 driver does not know which terminal is '/cDAQ1Mod1/ao/StartTrigger', because it is not a known terminal to the USB 6212 driver. What you have to do is to connect the two PFI terminal using a wire as described above. And then in your AO task export the start trigger out of the PFI terminals you added to the cDAQ 9174. And then in your AI task, set the source of the trigger as the PFI terminal of the USB 6212 that you have connected to.

 

If you have another AI module for the cDAQ 9174, you can use that instead of the USB 6212. Routing between cDAQ modules are made automatically by the driver since they are in the same chassis.

 

 

Message 2 of 4
(3,296 Views)

Hello Jerry,

 

Currently, I dont have NI 9401or 9402 for cDAQ 9174.

Thanks a lot for your help, I now get your points clearly.

 

 

0 Kudos
Message 3 of 4
(3,280 Views)

I have seen other questions on the topic on this forum, but none have helped me understand how to deal with this. Most of them also seem to me to be about quite intricated and long code.

0 Kudos
Message 4 of 4
(3,253 Views)