Clear Filters
Clear Filters

How do I change my trigger commands for a session based interface in the Data Acquisition Toolbox?

11 views (last 30 days)
I am trying to rewrite my Legacy based code for an analog input device into a Session based code, but it seems as if the Session based commands can not do everything that my Legacy code could. The goal is to change my code from version R2007b so that it will run the same on version R2017a.
Is there a way to convert all of these trigger properties into Session based code even if there isn't a direct corresponding translation?
AI = analoginput(nidaq,'Dev1');
chan = addchannel(AI,0:4);
set(AI,InputType,SingleEnded);
set(AI,SampleRate,5000);
duration = 2.0;
ActualRate = get(AI,SampleRate);
set(AI,SamplespPerTrigger,ActualRate*duration);
set(AI,TriggerChannel,chan(5));
set(AI,TriggerType,Software);
set(AI,TriggerCondition,Falling);
set(AI,TriggerConditionValue,0.0);
set(AI,TriggerRepeat,1);
set(AI,TriggerDelay,-1.2);
start(AI)
while strcmp(AI.Running,On)
end
[data,t] = getdata(AI);
delete(AI)
plot(t,data);
I have no trouble converting most of it but the biggest issue is finding a way to set a trigger delay of negative 1.2 seconds. Here is all that I have so far, which may not even be completely correct.
AI = daq.createSession(ni);
chan = addAnalogInputChannel(AI,Dev1,0:4,Voltage);
chan.TerminalConfig = SingleEnded;
AI.Rate = 5000;
AI.DurationInSeconds = 2.0;
addTriggerConnection(AI,External,Dev1/PFI0,StartTrigger);
AI.Connections(1).TriggerCondition = 'FallingEdge';
AI.TriggersPerRun = 2;
Thank you in advance for anyone who can help!

Accepted Answer

Abhi Sundararaman
Abhi Sundararaman on 2 Aug 2017
You're probably already using the following link to transition your code to session-based, but just in case, this link is very helpful: https://www.mathworks.com/help/daq/transition-your-code-to-session-based-interface.html#bt3hy26-1.
On the topic of "trigger delay", unfortunately the trigger delay property doesn't exist in the session based workflow. There are currently still some limitations on the session based workflow and this includes the lack of the "trigger delay" equivalent. The developers are aware of these limitations, and may consider them for future releases.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!