NI USB-6009 simultaneous input and output

25 views (last 30 days)
Jeff Duce
Jeff Duce on 6 Feb 2012
Edited: John Kelly on 22 Aug 2014
I need to program my USB-6009 to do the following task:
output a given DC voltage continuously
read analog input channels
change DC output
read input
... etc
But it won't allow me to run an input and output task at the same time. When I use the following code, I get the corresponding error:
Error using program (line 46)
The session contains channels that do not support clocked operations using startForeground and
startBackground. Only on-demand operations using inputSingleScan and outputSingleScan can be
How can I read multiple inputs while sending a simple DC output to the analog out channel?
I'm using Windows 7 64 bit, Matlab 2011b 64bit.

Answers (3)

Jeff Duce
Jeff Duce on 6 Feb 2012
Figured it out...
You have to create 2 sessions.
then associate only the inputs to one session and outputs to the other.
Next I'll try running it in a while loop. Hopefully that will work as well.
  1 Comment
Walter Roberson
Walter Roberson on 6 Feb 2012
What advantage do you see for using startForeground() compared to inputSingleScan() for your situation ?

Sign in to comment.

Walter Roberson
Walter Roberson on 6 Feb 2012
Edited: John Kelly on 22 Aug 2014
The part about the clocked operations I have not happened to encounter before. I did not find useful information in the time I searched.
Your overall structure does not appear to be correct:
If a session includes output channels, call queueOutputData before calling startForeground.
You cannot perform continuous operations using startForeground. To perform continuous operations use daq.Session.startBackground.
When you add analog output channels to the session, you must call queueOutputData() before calling startBackground().
From these I would understand that in order to read inputs while sending an output (at the same time), if your channels supported it, would require that you queue the output data and then start either a foreground or background operation. You have used outputSingleScan() to send a single output immediately but you have no other data queued, so you should consider whether simultaneous I/O is really appropriate for you even if you could get the clocking problem solved.
Walter Roberson
Walter Roberson on 6 Feb 2012
startForeground is for blocking operations, which is what you would get anyhow if you did a inputSingleScan(). So don't startForeground, just do inputSingleScan() as needed.
There is the natural question of whether the inputs from the channels would be synchronized. It appears to me, putting together some things I've read about how the session-based interface works, that the answer would be Yes when a single device is involved.

Sign in to comment.

mado on 8 Mar 2014
could i use this code for ni6008?


Find more on Simultaneous and Synchronized Operations 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!

Translated by