NI USB-6009 simultaneous input and output

20 vues (au cours des 30 derniers jours)
Jeff Duce
Jeff Duce le 6 Fév 2012
Modifié(e) : John Kelly le 22 Août 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.

Réponses (3)

Jeff Duce
Jeff Duce le 6 Fév 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 commentaire
Walter Roberson
Walter Roberson le 6 Fév 2012
What advantage do you see for using startForeground() compared to inputSingleScan() for your situation ?

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 6 Fév 2012
Modifié(e) : John Kelly le 22 Août 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 commentaires
Jeff Duce
Jeff Duce le 6 Fév 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 le 6 Fév 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.

Connectez-vous pour commenter.


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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by