Discover all other Devices Using the Legacy Interface

This example shows how to determine which hardware and adaptors are installed on your machine. It also shows you how to determine what Data Acquisition Toolbox™ objects can be created for each installed adaptor and what commands are needed to create those objects. Finally, it shows how to obtain help on data acquisition properties and functions.


Note: This can only be run using the 32-bit version of MATLAB® and Data Acquisition Toolbox™. To learn more about using data acquisition devices on other platforms, see this example.

First, find any running data acquisition objects and stop them. This stops all running data acquisition objects from interfering with this example. This code is usually not necessary outside this example unless there are multiple data acquisition objects running.

if (~isempty(daqfind))

In this example, we will determine:

  • What hardware and adaptors are installed on your machine

  • What Data Acquisition Toolbox objects you can create

  • How you can find information and help on a data acquisition object.

A hardware adaptor is the interface that allows you to pass information between the data acquisition engine and the hardware driver. The Data Acquisition Toolbox provides adaptors for:

  • Advantech® ('advantech')

  • Measurement Computing™ ('mcc')

  • National Instruments® ('nidaq')

  • parallel ports ('parallel')

  • sound cards ('winsound')

You can display information related to your hardware and to MATLAB® with the DAQHWINFO command.

daqhardwareinfo = daqhwinfo
daqhardwareinfo = 
          ToolboxName: 'Data Acquisition Toolbox'
       ToolboxVersion: '2.12 (R2008a)'
        MATLABVersion: '7.6 (R2008a)'
    InstalledAdaptors: {4x1 cell}

The returned information includes a list of installed hardware adaptors on your machine.

daqinstalledadaptors = daqhardwareinfo.InstalledAdaptors
daqinstalledadaptors = 

If you need to install an adaptor or move an existing adaptor, then it must be manually registered. A hardware adaptor is manually registered with the command:


where 'adaptorname' is one of the supported hardware adaptors such as 'winsound', 'nidaq', 'mcc', etc.

ans =
'mwwinsound.dll' successfully registered.

Now that we know what adaptors are installed on your computer, you can display specific information related to an adaptor by passing the adaptor name to DAQHWINFO. This information includes:

  • The hardware adaptor DLL filename and its version

  • The hardware driver description and its version

  • MATLAB commands for creating a data acquisition object using the specified adaptor name

The commands for creating a winsound data acquisition object are listed below.

daqwinsoundinfo = daqhwinfo('winsound')
daqwinsoundinfo = 
           AdaptorDllName: 'C:\Program Files\MATLAB\R2008a\toolbox\daq\daq\private\mwwinsound.dll'
        AdaptorDllVersion: '2.12 (R2008a)'
              AdaptorName: 'winsound'
               BoardNames: {'NVIDIA(R) nForce(TM) Audio'}
        InstalledBoardIds: {'0'}
    ObjectConstructorName: {'analoginput('winsound',0)'  'analogoutput('winsound',0)'  ''}

You can create both an analog input object and an analog output object for the winsound adaptor. The third returned value is empty because sound-cards do not support digital I/O.

ans =
ans =
ans =

Now that we know the command for creating an analog input object for the winsound adaptor, let's create it.

ai = analoginput('winsound', 0);
Display Summary of Analog Input (AI) Object Using 'NVIDIA(R) nForce(TM) Audio'.
  Acquisition Parameters:  8000 samples per second on each channel.
                           8000 samples per trigger on each channel.
                           1 sec. of data to be logged upon START.
                           Log data to 'Memory' on trigger.
      Trigger Parameters:  1 'Immediate' trigger(s) on START.
           Engine status:  Waiting for START.
                           0 samples acquired since starting.
                           0 samples available for GETDATA.
AI object contains no channels.

By default, the sound card uses 0 as the device id so it does not need to be specified. The following command illustrates this by creating an analog output object for the winsound adaptor.

ao = analogoutput('winsound');
Display Summary of Analog Output (AO) Object Using 'NVIDIA(R) nForce(TM) Audio'.
       Output Parameters:  8000 samples per second on each channel.
      Trigger Parameters:  1 'Immediate' trigger on START.
           Engine status:  Waiting for START.
                           0 total sec. of data currently queued for START.
                           0 samples currently queued by PUTDATA.
                           0 samples sent to output device since START.
AO object contains no channels.

You can find specific information pertaining to the created analog input object or analog output object by passing the object to DAQHWINFO. This information includes:

  • The number of channels that you can add to the object

  • The range of sample rates

  • The native data type

  • The polarity

ans = 
                AdaptorName: 'winsound'
                       Bits: 16
                   Coupling: {'AC Coupled'}
                 DeviceName: 'NVIDIA(R) nForce(TM) Audio'
            DifferentialIDs: []
                      Gains: []
                         ID: '0'
                InputRanges: [-1 1]
              MaxSampleRate: 44100
              MinSampleRate: 8000
             NativeDataType: 'int16'
                   Polarity: {'Bipolar'}
                 SampleType: 'SimultaneousSample'
             SingleEndedIDs: [1 2]
              SubsystemType: 'AnalogInput'
              TotalChannels: 2
    VendorDriverDescription: 'Windows Multimedia Driver'
        VendorDriverVersion: '5.10'

And for the analog output object:

ans = 
                AdaptorName: 'winsound'
                       Bits: 16
                 ChannelIDs: [1 2]
                   Coupling: {'AC Coupled'}
                 DeviceName: 'NVIDIA(R) nForce(TM) Audio'
                         ID: '0'
              MaxSampleRate: 44100
              MinSampleRate: 8000
             NativeDataType: 'int16'
               OutputRanges: [-1 1]
                   Polarity: {'Bipolar'}
                 SampleType: 'SimultaneousSample'
              SubsystemType: 'AnalogOutput'
              TotalChannels: 2
    VendorDriverDescription: 'Windows Multimedia Driver'
        VendorDriverVersion: '5.10'

By configuring property values for your data acquisition objects, you can control the behavior of your data acquisition application.

The Data Acquisition Toolbox device objects (analog input objects, analog output, and digital I/O objects) contain two kinds of properties:

 1) Base properties
 2) Device-specific properties

Base properties apply to all supported hardware subsystems of a given type (analog input, analog output, digital I/O). For example, all analog input objects have a SampleRate property regardless of the hardware vendor. In addition to the base properties, there may be a set of device-specific properties that is determined by the hardware you are using.

When PROPINFO is called with an object as the input argument, a structure is returned. The field names of the structure are the property names. The field values are a structure containing the property information. This information includes:

  • The property data type

  • Constraints on the property value

  • The default property value

  • Whether you can always modify this property, never modify it, or modify the property only when the object is not running

  • An indication of whether the property is device-specific

For example, you can obtain information on the SampleRate property with the command listed below. The information returned indicates that the SampleRate property:

  • Must be a double between the values 8000 and 44100

  • Has a default value of 8000

  • Can be modified only when the object is not running

  • Is a base property available to all analog input objects

aiInfo = propinfo(ai);
ans = 
               Type: 'double'
         Constraint: 'bounded'
    ConstraintValue: [8000 44100]
       DefaultValue: 8000
           ReadOnly: 'whileRunning'
     DeviceSpecific: 0

Alternatively, you can pass a property name to the PROPINFO command. In this case, information for the specified property is returned.

aoOut = propinfo(ao, 'TriggerType')
aoOut = 
               Type: 'string'
         Constraint: 'enum'
    ConstraintValue: {'Manual'  'Immediate'}
       DefaultValue: 'Immediate'
           ReadOnly: 'whileRunning'
     DeviceSpecific: 0

The information returned indicates that the TriggerType property:

  • Is of data type string.

  • Has a default value of 'Immediate'.

  • Can be modified only when the object is not running

  • Is a base property available to all analog output objects.

  • Is constrained to be an enumeration with the only acceptable values being 'Manual' and 'Immediate', as indicated by

ans = 
    'Manual'    'Immediate'

A more detailed property description is given with the DAQHELP command. The "See also" section that follows the description contains related properties and functions.

The related properties are displayed using mixed lower and upper case letters. The related functions are displayed using letters all in upper case.

daqhelp SampleRate

    SAMPLERATE  double

    SampleRate specifies the per-channel rate at which data is digitized.

    SampleRate specifies the per-channel rate (in samples/second) that the analog
    input (AI) or analog output (AO) subsystem digitizes data.

    AI and AO subsystems have a finite (though often large) number of valid
    sampling rates. If you specify a sampling rate that does not match one of
    the valid values, the data acquisition engine automatically selects
    the nearest available sampling rate.

    Since SampleRate can be set to a value that differs from the one specified, you
    should return the actual sampling rate using the GET function or the device
    object display summary. Alternatively, you can use the SETVERIFY function
    which sets the SampleRate value and then returns the actual value that is set.
    To find out the range of sampling rates supported by your board, use the
    PROPINFO function.

    The value of SampleRate cannot be modified while the object is running.


daqhelp StartFcn

    STARTFCN  string, function_handle, or cell array

    StartFcn specifies the function to execute just before the device
    object and hardware device start executing. 

    A start event is generated immediately after the START command is issued.
    This event executes the function specified for StartFcn.

    When the StartFcn function has finished executing, Running is automatically
    set to On and the device object and hardware device begin executing.

    Start event information is stored in the EventLog property.

    See also EventLog, Running.

DAQHELP can also be used to display Data Acquisition Toolbox function help. This can be useful in accessing a function's help since MATLAB requires that an object's classname be used for commands with multiple instances.

By using DAQHELP, you do not have to know an object's classname to get the correct help.

daqhelp delete
 DELETE Remove data acquisition objects from the engine.
     DELETE(OBJ) removes object, OBJ, from the data acquisition engine.
     If any channels or lines are associated with OBJ, they are also 
     deleted.  OBJ can be either a device array or a channel/line.
     If OBJ is the last object accessing the identified hardware, the
     associated hardware driver and driver specific adaptor are closed 
     and unloaded.
     Using CLEAR removes OBJ from the workspace only.
     DELETE should be used at the end of a data acquisition session.
     If OBJ is running, DELETE(OBJ) will delete OBJ and a warning 
     will be issued.  If OBJ is running and logging/sending, DELETE(OBJ)
     will not delete OBJ and an error will be returned.
     If multiple references to a data acquisition object exist in the 
     workspace, deleting one reference will invalidate the remaining 
     references.  These remaining references should be cleared from 
     the workspace.
       ai = analoginput('winsound');
       aiCopy = ai;

When finished, we delete the object and clear the variable from the workspace to free system resources.

Was this topic helpful?