| Data Acquisition Toolbox | Search  Help Desk |
Configuration
After initialization, a hardware device must be configured before a task can be executed. This essentially means setting up the device with the information necessary to carry out that task. In general, each type of device requires some configuration information that is specific to that device. For example, typical configuration information for a National Instruments board might be to collect two seconds of data from analog input hardware channels 0, 1, and 2 at a sampling rate of 10 kHz using dual channel DMA and single-ended inputs. The associated code for this configuration is shown below.AI = analoginput('nidaq', 1);
set(AI, 'SampleRate', 10000);
set(AI, 'InputType', 'SingleEnded');
set(AI, 'SamplesPerTrigger', 20000);
set(AI, 'TransferMode', 'DualDMA');
addchannel(AI, 0:2);
Any property value that is not explicitly set results in the default value for that property being used.
With the Data Acquisition Toolbox, configuration consists of two basic steps: mapping the hardware to a data acquisition object, and setting property values to establish the behavior of your acquisition. These steps are discussed below.
Mapping Hardware to Objects
To perform any data acquisition task, device objects must contain channels or lines. The resulting channel or line group consists of a mapping from hardware channels or lines to corresponding MATLAB indices. This mapping is done automatically when hardware channels or lines are added to a device object. For example, if hardware channels 0, 1, and 2 are added to the analog input objectAI
addchannel(AI, 0:2)
Setting Property Values
You can configure an existing device object by setting its property values. As described on page 2-15, all device objects, channels, and lines have a base set of properties that can be set. In addition to the base set of properties, there may be a set of device-specific properties, which is determined by the hardware you are using. You can use theset command to return all properties for AI and their possible values.
set(AI)
In addition to using theset(AI, 'SampleRate', 10000);set(AI, 'SamplesPerTrigger', 20000, 'InputType', 'SingleEnded');
set command to assign values to properties, you can use the standard MATLAB subscripted assignment syntax.
The advantage of theAI.SampleRate = 10000;AI.SamplesPerTrigger = 20000;AI.InputType = 'SingleEnded';
set syntax is that you can assign multiple property values with one call to set whereas with subscripted assignment, you can assign only one property value at a time.
Detailed procedures for configuring Data Acquisition Toolbox objects are given in Chapter 4, "Doing More With Analog Input."
Getting Property Values
You can evaluate the current object configuration by getting the property values. For example, you can use theget command to return all the current property names and property values for AI.
get(AI)
get(AI, 'SampleRate')
get(AI, {'SamplesPerTrigger', 'InputType'})
In addition to using the get command to return property values, you can use the standard MATLAB subscripted reference syntax.
For either syntax, if a left-hand-side variable is defined, then the returned values are captured in that variable.AI.SampleRateAI.SamplesPerTriggerAI.InputType
rate = get(AI, 'SampleRate')
type = AI.InputType
The advantage of the get syntax is you can return multiple property values with one command whereas with subscripted reference, you can return only one property value at a time.