Main Content

Using a Generic Driver at Command Line

Creating and Connecting the Device Object

The Instrument Control Toolbox™ software provides MATLAB® commands you can use in the Command Window or in files to create a device object that uses a driver, set and get properties of the object, and execute functions.

This example illustrates how to use the generic driver you created in Writing a Generic Driver.

  1. If your driver is not in the matlabroot\toolbox\instrument\instrument\drivers directory, in the MATLAB Command Window, make sure that the directory containing your driver is on the MATLAB software path.

    path

    If you do not see the directory in the path listing, and the driver is not in the matlabroot\toolbox\instrument\instrument\drivers directory, add the directory to the path with the command

    addpath directory

    where directory is the pathname to the directory containing your driver.

  2. Create a device object using your driver. For the driver used in this example, the icdevice function does not require an argument for a resource when using a generic driver. What the object connects to and how it makes that connection are defined in the Create code of your driver.

    ie_obj = icdevice('ie_drv');
  3. Connect the object.

    connect(ie_obj);

    When the device object is connected, an empty IE window appears on your screen. Now you can communicate directly with the IE browser from the MATLAB Command window.

Accessing Properties

The driver you created allows you to specify where the browser window appears on your screen and how large it is. You read and write the properties of your device object with the get and set functions, respectively.

  1. View all of the properties of your device object.

    get(ie_obj)
        ConfirmationFcn = 
        DriverName = ie_drv.mdd
        DriverType = MATLAB generic
        InstrumentModel = 
        Interface = [1x1 COM.internetexplorer_application]
        LogicalName = 
        Name = Browser-ie_drv
        ObjectVisibility = on
        RsrcName = 
        Status = open
        Tag = 
        Timeout = 10
        Type = Browser
        UserData = []
    
        BROWSER specific properties:
        Top = 47
        Vsize = 593
    
  2. Most of the properties listed belong to all device objects. For this example, the properties of interest are those listed as BROWSER specific properties, that is, Top and Vsize.

    The Top property defines the IE browser window position in pixels from the top of the screen. Vsize defines the vertical size of the window in pixels.

  3. Shift the IE browser window to the top of the screen.

    ie_obj.Top = 0;
  4. With the mouse, grab and drag the IE browser window down away from the top of the screen.

  5. Find the window's new position by examining the Top property.

    ie_obj.Top
    ans =
       120

    Adjust the size of the window by setting the Vsize property.

    ie_obj.Vsize = 200);
  6. Make the window larger by increasing the property value.

    ie_obj.Vsize = 600);

Using Functions

By using the goTo function of your generic driver, you can control the Web page displayed in the IE browser window.

  1. View all of the functions (methods) of your device object.

    methods(ie_obj)
    
    Methods for class icdevice:
    
    Contents    disp       icdevice      instrnotify methods   size 
    class       display    igetfield     instrument  ne        subsasgn 
    close       end        inspect       invoke      obj2mfile subsref 
    connect     eq         instrcallback isa         open      vertcat 
    ctranspose  fieldnames instrfind     isequal     openvar 
    delete      get        instrfindall  isetfield   propinfo 
    devicereset geterror   instrhelp     isvalid     selftest 
    disconnect  horzcat    instrhwinfo   length      set 
    
    Driver specific methods for class icdevice:
    
    goTo

    Most of the methods listed apply to all device objects. For this example, the method of interest is the one listed under Driver specific methods, that is, goTo.

  2. Use the goTo function to specify the page for the IE browser to display.

    invoke(ie_obj, 'goTo', 'www.mathworks.com');

    If you have access to the Internet, the IE window should display the MathWorks Web site.

  3. When you are finished with your example, clean up the MATLAB workspace by removing the object.

    disconnect(ie_obj);
    delete(ie_obj);
    clear ie_obj;
  4. Close the IE browser window you created in this example.