| Data Acquisition Toolbox | ![]() |
Starting Multiple Device Objects
With the Data Acquisition Toolbox, you can start multiple device objects. You may find this feature useful when simultaneously using your hardware's analog output (AO) and analog input (AI) subsystems. For example, suppose you create the analog input object ai and the analog output object ao for a sound card, and add one channel to each device object.
ai = analoginput('winsound');
addchannel(ai,1);
ao = analogoutput('winsound');
addchannel(ao,1);
You should use manual triggers when starting multiple device objects since this trigger type executes faster than other trigger types with the exception of hardware triggers. Additionally, to synchronize the input and output of data, you should configure the ManualTriggerHwOn property to Trigger for ai.
set([ai ao],'TriggerType','Manual') set(ai,'ManualTriggerHwOn','Trigger')
Configure ai for continuous acquisition, call the action function qmoredata whenever 1000 samples are output, and call daqaction when ai and ao stop running.
set(ai,'SamplesPerTrigger',inf)
set(ao,'SamplesOutputAction',{'qmoredata',ai})
set(ao,'SamplesOutputActionCount',1000)
set([ai ao],'StopAction','daqaction')
As shown below, the action function qmoredata extracts data from the engine and then queues it for output.
function qmoredata(obj,event,ai) data = getdata(ai,1000); putdata(obj,data)
Queue data in the engine, start the device objects, and execute the manual triggers.
data = zeros(4000,1); putdata(ao,data) start([ai ao]) trigger([ai ao])
You can determine the starting time for each device object with the InitialTriggerTime property. The difference, in seconds, between the starting times for ai and ao is
aitime = ai.InitialTriggerTime
aotime = ao.InitialTriggerTime
delta = abs(aotime - aitime);
sprintf('%d',delta(6))
ans =
2.288818e-005
Note that this number depends on the specific platform you are using. To stop both device objects
stop([ai ao])
The output from daqaction is shown below.
Stop event occurred at 13:00:25 for the object: winsound0-AO. Stop event occurred at 13:00:25 for the object: winsound0-AI.
| Example: Performing a Linear Conversion | Digital Input/Output | ![]() |