| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Data Acquisition Toolbox |
| Contents | Index |
| Learn more about Data Acquisition Toolbox |
| On this page… |
|---|
Device objects are the toolbox components you use to access your hardware device. They provide a gateway to the functionality of your hardware, and allow you to control the behavior of your data acquisition application. Each device object is associated with a specific hardware subsystem.
To create a device object, you call M-file functions called object creation functions (or object constructors). These M-files are implemented using the object-oriented programming capabilities provided by the MATLAB software, which are described in the chapters Classes (Data Types) and Using Objects in the MATLAB Programming Fundamentals documentation. The device object creation functions are listed below.
Device Object Creation Functions
Function | Description |
|---|---|
Create an analog input object. | |
Create an analog output object. | |
Create a digital I/O object. |
Before you can create a device object, the associated hardware driver adaptor must be registered. Adaptor registration occurs automatically. However, if for some reason an adaptor is not automatically registered, then you must do so manually with the daqregister function. Refer to Registering the Hardware Driver Adaptor for more information.
You can find out how to create device objects for a particular vendor and subsystem with the ObjectConstructorName field of the daqhwinfo function. For example, to find out how to create an analog input object for an installed National Instruments board, you supply the appropriate adaptor name to daqhwinfo.
out = daqhwinfo('nidaq');
out.ObjectConstructorName(:)
ans =
'analoginput('nidaq','Dev1')'
'analogoutput('nidaq','Dev1')'
'digitalio('nidaq','Dev1')'The constructor syntax tells you that you must supply the adaptor name and the hardware ID to the analoginput function
ai = analoginput('nidaq','Dev1');The association between device objects and hardware subsystems is shown below.

In the MATLAB workspace, you can create an array from existing variables by concatenating those variables together. The same is true for device objects. For example, suppose you create the analog input object ai and the analog output object ao for a sound card:
ai = analoginput('winsound');
ao = analogoutput('winsound');You can now create a device object array consisting of ai and ao using the usual MATLAB syntax. To create the row array x:
x = [ai ao] Index: Subsystem: Name: 1 Analog Input winsound0-AI 2 Analog Output winsound0-AO
To create the column array y:
y = [ai;ao];
Note that you cannot create a matrix of device objects. For example, you cannot create the matrix
z = [ai ao;ai ao]; ??? Error using ==> analoginput/vertcat Only a row or column vector of device objects can be created.
Depending on your application, you might want to pass an array of device objects to a function. For example, using one call to the set function, you can configure both ai and ao to the same property value.
set(x,'SampleRate',44100)
Refer to Functions — Alphabetical List to see which functions accept a device object array as an input argument.
When you create a device object, it exists in both the MATLAB workspace and the data acquisition engine. For example, suppose you create the analog input object ai for a sound card and then make a copy of ai.
ai = analoginput('winsound');
newai = ai;The copied device object newai is identical to the original device object ai. You can verify this by setting a property value for ai and returning the value of the same property from newai.
set(ai,'SampleRate',22050);
get(newai,'SampleRate')
ans =
22050As shown below, ai and newai return the same property value because they both reference the same device object in the data acquisition engine.

If you delete either the original device object or a copy, then the engine device object is also deleted. In this case, you cannot use any copies of the device object that remain in the workspace because they are no longer associated with any hardware. Device objects that are no longer associated with hardware are called invalid objects. The example below illustrates this situation.
delete(ai); newai newai = Invalid Data Acquisition object. This object is not associated with any hardware and should be removed from your workspace using CLEAR.
You should remove invalid device objects from the workspace with the clear command.
![]() | Understanding the Data Acquisition Session | Hardware Channels or Lines | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |