Queues data to be output
result = mdaqAOScanData(channels, data, opt)
This function is part of analog scan functionality and has to be called in the following sequence:
Initialize scanning session - mdaqAOScanInit()
Start scanning session - mdaqAOScan()
Queue new data - mdaqAOScanData()
Stop scanning session - mdaqAOScanStop()
This function queues data to be output. A function call has to be preceded with mdaqAOScanInit(). Function queues data in the stream and periodic mode and its behavior depends on selected scan mode. In periodic mode, the function can queue data for every channel combination from used channels (defined in mdaqAOScanInit()). If e.g. in scanning session four channels are used: 1, 2, 3, 4 mdaqAOScanData() can be called to queue data for 1 or 4 or 1,2 or 1,4, or 3,4 etc. channel or queue data for all selected channels. In periodic mode channels argument can contain every combination of used channels, while in stream mode channel argument must be the same as used in mdaqAOScanInit(). The data argument in stream mode must have the same size as the data argument in function mdaqAOScanInit(). The mdaqAOScanInit() perform initial data queue operation. The periodic mode uses a single buffer which data is output from. When the end of the buffer is reached, data index is switched to the beginning of the buffer. The mdaqAOScanData() function overwrites the whole buffer with new data. Depending on the scanning mode opt argument has a different meaning. When the periodic mode is used opt argument allows controlling data index after queuing data. When opt=%T data index will be set to the beginning of the buffer. If opt=%F queue operation doesn't affect data index.
When stream mode is used opt argument determines blocking or non-blocking operation of mdaqAOScanData(). The blocking operation (opt=true) will block Matlab console until data is queued. The stream mode uses two buffers to ensure uninterrupted analog signal generation. Queuing data is only possible when one buffer is empty, if both are queued function will wait(opt=true) or return negative result(opt=false). In blocking mode mdaqAOScanData() has 1 second time-out. If non-blocking operation (opt=false) is used function will return immediately with result containing a number of queued data.
Data has to be queued before data index reaches the end of previously queued data. Otherwise, last value will remain on analog output.
channels: channel vector
data: Output data values, specified as an m-by-n matrix, where m is the number of scans to generate, and n is the number of used output channels. Must be same size as initial data argument in mdaqAOScanInit()
opt: Reset data index after upload (Periodic mode). Blocking / non-blocking operation (Stream mode) (true / false)
Queue output data (initial data) for a single channel in periodic mode
data0 = linspace(0,2,1000)'; mdaqAOScanInit(1, data0, [0,5], false, 1000, 10); mdaqAOScan();
Queue output data (initial data) for multiple channel in periodic mode
data0 = linspace(0,1,1000)'; data1 = linspace(0,2,1000)'; mdaqAOScanInit(1:2, [data0 data1], [0,5], false, 1000, 10); mdaqAOScan();
Generate sine waveform (AO1) with increasing amplitude and acquire data from analog input (AI1) simultaneously. In this example analog output session uses stream mode. Analog output data (sine waveform) is queued in the loop. Using blocking mode for analog output and input sessions ensures function call synchronization.
aiData = []; channels = 1 rate = 1000; scanDataSize = 1000; duration = 5; expValue = -3; sineBias = 2.5; sineBase = sin(linspace(0, 2*pi, scanDataSize)); expWave = exp(linspace(expValue, expValue + 0.8, scanDataSize)); sineWave = sineBase.*expWave + sineBias; % initialize analog input/output scanning sessions mdaqAOScanInit(channels, sineWave', [-10,10], true, rate, duration); mdaqAIScanInit(channels, [-10,10], false, rate, duration); % start AI scanning without waiting for data mdaqAIScan(0, true); % start signal generation mdaqAOScan(); n = (rate * duration) / scanDataSize; for i=1:n-1 expValue = expValue + 0.8; expWave = exp(linspace(expValue, expValue + 0.8, scanDataSize)); sineWave = sineBase.*expWave + sineBias; % queue new data mdaqAOScanData(channels, sineWave', true); % start and acquire data from analog inputs aiData = [aiData; mdaqAIScan(scanDataSize, true)]; end % acquire rest of samples aiData = [aiData; mdaqAIScan(scanDataSize, true)]; plot(aiData) clear aiData;
Results: