NI USB-6009 simultaneous input and output

12 次查看(过去 30 天)
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:
s=daq.createSession('ni');
s.Rate=rate;
s.DurationInSeconds=sampletime;
ch=s.addAnalogInputChannel('Dev1',0:2,'Voltage');
chout=s.addAnalogOutputChannel('Dev1',1,'Voltage');
s.outputSingleScan(1);
[data,timeStamp,triggerTime]=s.startForeground();
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
done.
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.

回答(3 个)

Jeff Duce
Jeff Duce 2012-2-6
Figured it out...
You have to create 2 sessions.
s=daq.createSession('ni');
s1=daq.createSession('ni');
then associate only the inputs to one session and outputs to the other.
ch=s.addAnalogInputChannel('Dev1',0:2,'Voltage');
chout=s1.addAnalogOutputChannel('Dev1',1,'Voltage');
s1.outputSingleScan(1);
[data,timeStamp,triggerTime]=s.startForeground();
s1.outputSingleScan(0);
Next I'll try running it in a while loop. Hopefully that will work as well.
  1 个评论
Walter Roberson
Walter Roberson 2012-2-6
What advantage do you see for using startForeground() compared to inputSingleScan() for your situation ?

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2012-2-6
编辑:John Kelly 2014-8-22
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.
  2 个评论
Jeff Duce
Jeff Duce 2012-2-6
If I queue an output (I used linspace(1,1,100)');), I get the following 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
done.
So what I am understanding is that I cannot have a clocked output, only a single value. This is fine, because this is what I want. But when I call the startForeground, it wants to start both the input and output channels as clocked input/output. I only want it to start in the input channel. Is there a way to do that?
Walter Roberson
Walter Roberson 2012-2-6
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.

请先登录,再进行评论。


mado
mado 2014-3-8
could i use this code for ni6008?

类别

Help CenterFile Exchange 中查找有关 Simultaneous and Synchronized Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by