NI USB-6009 simultaneous input and output

11 visualizaciones (últimos 30 días)
Jeff Duce
Jeff Duce el 6 de Feb. de 2012
Editada: John Kelly el 22 de Ag. de 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:
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.

Respuestas (3)

Jeff Duce
Jeff Duce el 6 de Feb. de 2012
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 comentario
Walter Roberson
Walter Roberson el 6 de Feb. de 2012
What advantage do you see for using startForeground() compared to inputSingleScan() for your situation ?

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 6 de Feb. de 2012
Editada: John Kelly el 22 de Ag. de 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.
  2 comentarios
Jeff Duce
Jeff Duce el 6 de Feb. de 2012
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 el 6 de Feb. de 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.

Iniciar sesión para comentar.


mado
mado el 8 de Mzo. de 2014
could i use this code for ni6008?

Categorías

Más información sobre Simultaneous and Synchronized Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by