How do I run multiple background operations (ie, "startBackground")

2 views (last 30 days)
I'm having trouble sending multiple simultanious outputs to the same DAQ. Here's the realavent part of my code:
%% initialize DAQ
daqreset
%laser controller
sLaser = daq.createSession('ni');
sLaser.addAnalogOutputChannel('Dev1','ao0','Voltage');
sLaser.Rate = 2000;
%estim controller
sElectro = daq.createSession('ni');
sElectro.addAnalogOutputChannel('Dev1','ao1','Voltage');
sElectro.Rate = 2000;
stim_pattern_output=[0 0 0 5 5 5 0 0 0 5 5 5]; %not the actual output, but it'll give you an idea
stim_pattern_output=stim_pattern_output';
queueOutputData(sElectro, stim_pattern_output)
startBackground(sElectro)
queueOutputData(sLaser, stim_pattern_output)
startBackground(sLaser)
Ultimately, when we get to "startBackground(sLaser)" I get the error "The hardware associated with this session is reserved. If you are using it in another session use the release function to unreserve the hardware. If you are using it in an external program exit that program. Then try this operation again."
Is there a workaround for this? I'm a bit new to the program, but I cannot imagine there's such a major limiting factor to DAQ useable with MATLAB to only allow one output/daq at a time.

Answers (1)

Kavya Vuriti
Kavya Vuriti on 25 Mar 2020
Hi,
To output on two analog output channels from the same device, you can add two channels on same session.
In this case, the reserved hardware error is expected because the vendor's NI-DAQmx driver does not allow two separate connections to the same subsystem at once.

Categories

Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!