Contents

Creating a Stub Adaptor

The easiest way to start building an adaptor is to create a stub implementation, compile and link it, and then test your work. This method can be effective because it provides immediate results and lets you verify that your build environment is setup properly.

This section shows a stub implementations of an adaptor that you can copy and paste into a file in your adaptor Microsoft® Visual C++® project. After compiling and linking this code, you can see your adaptor included in the list of available adaptors returned by the imaqhwinfo function.

    Note   You will not be able to instantiate an object of your adaptor class, however. That is described in Defining Your Adaptor Class.

To create a stub adaptor, follow this procedure:

  1. Add a C++ source file to the adaptor C++ project. See Setting up a Build Environment on Windows Systems for information about creating an adaptor C++ project. This source file will hold your implementations of your adaptor's exported C++ functions. You can give this file any name. This example uses the name of the adaptor for this file, with the text string "_exported_fcns" appended to it, mydevice_exported_fcns.cpp

  2. Copy the following lines of C++ code into this new file. This code provides stub implementations of the required adaptor exported functions. Note that you must include the adaptor kit header file mwadaptorimaq.h. This header file includes all other required adaptor kit header files. The getDeviceAttributes() stub defines a video source—see Identifying Video Sources for more information.

    #include "mwadaptorimaq.h"
    
    void initializeAdaptor(){
    
    }
    void getAvailHW(imaqkit::IHardwareInfo* hardwareInfo){ 
     
    }
    
    void getDeviceAttributes(const imaqkit::IDeviceInfo* deviceInfo,
    	                                        const char* formatName,
                              imaqkit::IPropFactory* devicePropFact,
                         imaqkit::IVideoSourceInfo* sourceContainer,
                               imaqkit::ITriggerInfo* hwTriggerInfo){
    
        // Create a video source
        sourceContainer->addAdaptorSource("MyDeviceSource", 1);
    
    }
    
    imaqkit::IAdaptor* createInstance(imaqkit::IEngine* engine, const
                              imaqkit::IDeviceInfo* deviceInfo, const 
                                              char* formatName){
        
        imaqkit::IAdaptor* adaptor = NULL;
        return adaptor;
    }
    
    void uninitializeAdaptor(){ 
    
    }
    
  3. Build the adaptor DLL. Select the Build Solution option on the Build menu.

  4. Start the MATLAB® software.

  5. Tell the toolbox where to find this new adaptor using the imaqregister function. See Registering an Adaptor with the Toolbox for more information. You only need to perform this step once.

  6. Call the imaqhwinfo function. Note that the stub adaptor, named mydeviceimaq, is included in the list of available adaptors returned.

    imaqhwinfo
    
    ans = 
    
        InstalledAdaptors: {'demo'  'mydeviceimaq'  'winvideo'}
            MATLABVersion: '7.12 (R2011a)'
              ToolboxName: 'Image Acquisition Toolbox'
           ToolboxVersion: '4.1 (R2011a)'

    To get more information about the stub adaptor, call imaqhwinfo again, this time specifying the name of the adaptor.

      Note:   At this point in your adaptor development, the DeviceIDs field and the DeviceInfo fields are empty.

    imaqhwinfo('mydeviceimaq')
    
    ans = 
    
           AdaptorDllName: 'C\My_Adaptor\mydeviceimaq.dll'
        AdaptorDllVersion: '4.1 (R2011a)'
              AdaptorName: 'mydeviceimaq'
                DeviceIDs: {1x0 cell}
               DeviceInfo: [1x0 struct]
    
Was this topic helpful?