Using National Instruments USB-6259
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to re-write the function for NI USB-6259 data acquisition system using the session-based interface.
The old code looks like this:
function data = In_Out_DAQpad1(sig, fs, iRange)
ao = analogoutput('nidaq', 'Dev1');
ai = analoginput('nidaq', 'Dev1');
out_chan = addchannel(ao, 2);
in_chan = addchannel(ai, 2:2);
ai.SampleRate = fs;
ao.SampleRate = fs;
ai.TriggerType = 'Immediate';
ai.ExternalTriggerDriveLine = 'PFI0';
ao.TriggerType = 'HwDigital';
ao.HwDigitalTriggerSource = 'PFI0';
ao.TriggerCondition = 'PositiveEdge';
ao.Channel.OutputRange = [-5 5];
ao.Channel.UnitsRange = [-5 5];
ai.InputType = 'Differential';
set(ai.Channel, 'InputRange', [-iRange iRange]);
ai.SamplesPerTrigger = length(sig)+round(fs*0.1);
putdata(ao,sig)
start(ao);
start(ai);
wait(ao,1+ceil(length(sig)/fs));
data = getdata(ai);
delete(ao);
delete(ai);
clear ao
How would I re-write this as a session-based friendly script? Here's what I have so far...
function data=In_Out_DAQPad1(sig,fs,iRange)
s=daq.createSession('ni');
ao=addAnalogOutputChannel(s,'Dev1',2,'Voltage');
ai=addAnalogInputChannel(s,'Dev1',2,'Voltage');
s.rate=fs;
addTriggerConnection(s,'External','Dev1/PFI0','StartTrigger');
ch=addAnalogInputChannel(s,'Dev1',1,'Voltage');
ch.Range=[-5 5];
ai.InputType='Differential';
set(ai.Channel,'InputRange',[-iRange iRange]);
ai.SamplesPerTrigger=length(sig)+round(fs*0.1);
putdata(ao,sig)
startForeground(s);
wait(ao,1+ceil(length(sig)/fs));
data=getdata(ai);
delete(ao);
delete(ai);
clear ao
When I try and execute this, I get the error No public property rate exists for class daq.ni.Session.
As you can tell, I'm very new to all this so any help would be greatly obliged.
Many thanks in advance.
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Instrument Control Toolbox Supported Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!