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
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.
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.
Figured it out...
You have to create 2 sessions.
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.
Play games and win prizes!Learn more