How do I perform buffered digital I/O using the Data Acquisition Toolbox?

2 views (last 30 days)
I need to be able to set up a buffered acquisition with external trigger and external clock and use a DMA transfer after the acquistion is completed. I would like to know the complexity level with doing this with the Data Acquisition Toolbox.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Apr 2012
This enhancement has been incorporated in Release 2012a (R2012a). For previous product releases, read below for any possible workarounds:
The Data Acquisition Toolbox does not directly support buffered DIO or handshaking (latching) at this time. However, you can write your own MATLAB code to support this functionality.
If you want to do it in MATLAB code using callbacks, here is an example showing how to do it. This example is for output.
1. Create a MATLAB file to handle the output. The file should be saved as dooutput.m (for the example; it can be named anything for other instances) and have the following contents:
function dooutput(obj, event)
% The UserData field is the common way of passing data around.
% In this example it holds a struct with two fields, 'count'
% the number of times the function has been called and 'data'
% which is the data to be output.
outdata = obj.UserData
if (outdata.count < length(outdata.data))
outdata.count = outdata.count + 1;
putvalue(obj, outdata.data(outdata.count, :));
else
stop(obj)
end
obj.Userdata = outdata;
% end of MATLAB file
2. In MATLAB do the following:
% Generate the output data.
data = myData(...);
% Create the object, add the dio lines
obj = dio('nidaq', 1);
addline(obj, 1:8, 'out');
% Configure the callbacks
obj.TimerFcn = @dooutput;
obj.TimerPeriod = .01;
% Setup the userdata
outdata.count = 0;
outdata.data = data;
obj.UserData = outdata;
% Start the output
start(obj)

More Answers (0)

Categories

Find more on Simultaneous and Synchronized Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!