Main Content

Creating and Connecting Device Objects

Device Objects for MATLAB Interface Drivers

Create a MATLAB® device object to communicate with a Tektronix® TDS 210 Oscilloscope. To communicate with the scope you will use a National Instruments™ GPIB controller.

  1. First create an interface object for the GPIB hardware. The following command creates a GPIB object for a National Instruments GPIB board at index 0 with an instrument at primary address 1.

    g = gpib('ni',0,1);
  2. Now that you have created the interface object, you can construct a device object that uses it. The command to use is icdevice. You need to supply the name of the instrument driver, tektronix_tds210, and the interface object created for the GPIB controller, g.

    d = icdevice('tektronix_tds210', g);

You can use the whos command to display the size and class of d.

whos d
  Name      Size                   Bytes  Class

  d         1x1                      652  icdevice object

Grand total is 22 elements using 652 bytes

Device Object Properties

A device object has a set of base properties and a set of properties defined by the driver. All device objects have the same base properties, regardless of the driver being used. The driver properties are defined by the driver specified in the icdevice constructor.

Device Object Display

Device objects provide you with a convenient display that summarizes important object information. You can invoke the display in these ways:

  • Type the name of the device object at the command line.

  • Exclude the semicolon when creating the device object.

  • Exclude the semicolon when configuring properties using dot notation.

  • Pass the object to the disp or display function.

The display summary for device object d is given below.

Instrument Device Object Using Driver : tektronix_tds210.mdd

    Instrument Information
      Type:               Oscilloscope
      Manufacturer:       Tektronix
      Model:              TDS210

   Driver Information
      DriverType:         MATLAB interface object
      DriverName:         tektronix_tds210.mdd
      DriverVersion:      1.0

   Communication State
      Status:             open

You can also display summary information via the Workspace browser by right-clicking a device object and selecting Display Summary from the context menu.

Device Objects for VXIplug&play and IVI Drivers

Note

The MATLAB instrument driver functions makemid, midedit, and midtest will be removed in a future release. Use the ividev interface from the Instrument Control Toolbox™ Support Package for IVI® and VXIplug&play Drivers instead. For more information, see IVI and VXIplug&play Drivers.

Creating the MATLAB Instrument Driver

The command-line function makemid creates a MATLAB instrument driver from a VXIplug&play or IVI-C driver, saving the new driver in a file on disk. The syntax is

makemid('driver','filename')

where driver is the original VXIplug&play or IVI-C driver name, and filename is the file containing the newly created MATLAB instrument driver. See the makemid reference page for a full description of the function and all its options.

You can open the new driver in the MATLAB Instrument Driver Editor, and then modify and save it as required.

Creating the Device Object

After you create the MATLAB instrument driver by conversion, you create the device object with the filename of the new driver as an argument for icdevice.

For example, if the driver is created from a VXIplug&play or IVI-C driver,

obj = icdevice('ConvertedDriver.mdd','GPIB0::2::INSTR')

Connecting the Device Object

Now that you have created the device object, you can connect it to the instrument with the connect function. To connect the device object, d, created in the last example, use the following command:

connect(d);

By default, the property settings are updated to reflect the current state of the instrument. You can modify the instrument settings to reflect the device object's property values by passing an optional update parameter to connect. The update parameter can be either object or instrument. To have the instrument updated to the object's property values, the connect function from the previous example would be

connect(d, 'instrument');

If connect is successful, the device object's status property is set to open; otherwise it remains as closed. You can check the status of this property with the get function or by looking at the object display.

d.status

ans =

    open