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

Writing to two output channels simultaneously crashes nidaqmx (python)

$
0
0

Hello everyone

 

I'm a new user of NI boards and am a bit lost with a dual stream_writers problem that I can't seem to find a solution to.

 

I'm trying to use a NI 6229 card with 2 x BNC-2090A (or even a single one) to send periodic simultaneous TTL pulses. One TTL pulse controls a speaker (plays sound waves) the other opens a port for a water release valve.

 

Independently, these two tasks are easy to do using the

 

 

 

 

 

 

 

nidaqmx.stream_writers.AnalogSingleChannelWriter()

 

 

 

 

 

 

 

function and these individual commands:

 

 

 

 

 

 

 

water_Writer.write_one_sample(5) audio_Writer.write_many_sample(tone)

 

 

 

 

 

 

 

But when I run them in series (i.e. without closing the first one), I get this error when the second task tries to write:

 

 

 

 

 

 

 

DaqWriteError: The specified resource is reserved. The operation could not be completed as specified. Task Name: _unnamedTask<4>

 

 

 

 

 

I've added a 2nd BNC-2090A breakout board (see ao2 above) and I get the same error. I do have a 2nd 6229 card - but! my computer doesn't have any more slots to insert it into.

 

Should I not be using the stream-writers function to write TTL output? 

 

Any advice is much appreciate! As I said, I'm quite new at NI + python configuration and a bit lost.

Thanks so much,

Catalin

 

Here's the entirety of my code, including a function that converts frequency values to oscillations playable via TTL pulse:

 

 

 

 

 

 

######################################################## #################### HYBRID RUN ######################## ######################################################## def make_tone(f, amp, duration): fs = 200000 # 200kHz (Sample Rate) T = 1/f Ts = 1/fs x = np.arange(int(fs*duration)) y = [ amp*np.sin(2*np.pi*f * (i/fs)) for i in x] y_new = np.tile(y,1) return y_new # import nidaqmx # Initialize speaker task; audio_Task = nidaqmx.Task() # audio_Task.ao_channels.add_ao_voltage_chan('Dev3/ao0') audio_Task.timing.cfg_samp_clk_timing(rate = 200000, sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS) # audio_Writer = nidaqmx.stream_writers.AnalogSingleChannelWriter(audio_Task.out_stream, auto_start=True) # Initialize water task water_Task = nidaqmx.Task() water_Task.ao_channels.add_ao_voltage_chan('Dev3/ao2') water_Task.timing.cfg_samp_clk_timing(rate = 200000, sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS) # water_Writer = nidaqmx.stream_writers.AnalogSingleChannelWriter(water_Task.out_stream, auto_start=True) #################################################### # realtime streaming with callback amp = 0.003 # tone amplitude in ? duration = 0.1 # tone duration in seconds; ctr=0 freq = 1000 tone = make_tone(freq, amp, duration) # duration = 50000 # time in 100000Hz time base (?) for k in range(25): for p in range(duration): water_Writer.write_one_sample(5) audio_Writer.write_many_sample(tone) # water_Task.stop() water_Task.close() audio_Task.stop() audio_Task.close()

 

 

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 2147

Trending Articles



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