To create a stub implementation of your adaptor class, follow this procedure:
Add a C++ header file to the adaptor C++ project. This header file will hold the definition of your adaptor class. You can give your class any name. This example uses the following naming convention:
vendor_name + adaptor
For this example, the header file that contains the adaptor
class definition is named MyDeviceAdaptor.h
.
Copy the following class definition
into the header file. This adaptor class contains all the virtual
functions defined by the IAdaptor
abstract class.
#include "mwadaptorimaq.h" // required header class MyDeviceAdaptor : public imaqkit::IAdaptor { public: // Constructor and Destructor MyDeviceAdaptor(imaqkit::IEngine* engine, const imaqkit::IDeviceInfo* deviceInfo, const char* formatName); virtual ~MyDeviceAdaptor(); // Adaptor and Image Information Functions virtual const char* getDriverDescription() const; virtual const char* getDriverVersion() const; virtual int getMaxWidth() const; virtual int getMaxHeight() const; virtual int getNumberOfBands() const; virtual imaqkit::frametypes::FRAMETYPE getFrameType() const; // Image Acquisition Functions virtual bool openDevice(); virtual bool closeDevice(); virtual bool startCapture(); virtual bool stopCapture(); };
Add a C++ source file to the adaptor
project. You can give the source file any name. This example names
the file mydeviceadaptor.cpp
.
Copy the following stub implementations of all the adaptor virtual functions into the C++ source file.
#include "MyDeviceAdaptor.h" #include "mwadaptorimaq.h" // Class constructor MyDeviceAdaptor::MyDeviceAdaptor(imaqkit::IEngine* engine, const, imaqkit::IDeviceInfo* deviceInfo, const char* formatName):imaqkit::IAdaptor(engine){ } // Class destructor MyDeviceAdaptor::~MyDeviceAdaptor(){ } // Device driver information functions const char* MyDeviceAdaptor::getDriverDescription() const{ return "MyDevice_Driver"; } const char* MyDeviceAdaptor::getDriverVersion() const { return "1.0.0"; } // Image data information functions int MyDeviceAdaptor::getMaxWidth() const { return 640;} int MyDeviceAdaptor::getMaxHeight() const { return 480;} int MyDeviceAdaptor::getNumberOfBands() const { return 1;} imaqkit::frametypes::FRAMETYPE MyDeviceAdaptor::getFrameType() const { return imaqkit::frametypes::MONO8; } // Image acquisition functions bool MyDeviceAdaptor::openDevice() {return true;} bool MyDeviceAdaptor::closeDevice(){return true;} bool MyDeviceAdaptor::startCapture(){return true;} bool MyDeviceAdaptor::stopCapture(){return true;}
Add a reference to your adaptor class
header file to the file containing the exported functions, mydevice_exported_fcns.cpp
,
that you created in Using Adaptor Exported Functions. This is needed because
the createInstance()
exported function instantiates
an object of this class.
#include "MyDeviceAdaptor.h"
Edit the stub implementations of the createInstance()
function,
also in the exported functions source file, mydevice_exported_fcns.cpp
.
Make the function instantiate an object of your adaptor class, highlighted
in italics below. (In the stub, it returns NULL
.)
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, imaqkit::IDeviceInfo* deviceInfo, char* formatName){ imaqkit::IAdaptor* adaptor = new MyDeviceAdaptor(engine,deviceInfo,formatName); return adaptor; }
Build the adaptor DLL. Select the Build Solution option on the Build menu.
Start the MATLAB® software.
Call the imaqhwinfo
function.
Note how the adaptor, named mydeviceimaq
, is included
in the list of available adaptors returned by imaqhwinfo
.
If you have not previously registered your adaptor DLL, register your
adaptor with the toolbox — see Registering an Adaptor with the Toolbox.
To view more detailed information about your adaptor, call imaqhwinfo
again
with this syntax:
dev_info = imaqhwinfo('mydeviceimaq');
Create a video input object for the mydeviceimaq
adaptor,
using the videoinput
function.
Note
While you can create a video input object with your adaptor, you cannot use it to acquire video from a device. You must implement the adaptor class acquisition functions to do that. See Acquiring Image Data for more information.
vid = videoinput('mydeviceimaq',1) Summary of Video Input Object Using 'MyDevice'. Acquisition Source(s): MyDeviceSource is available. Acquisition Parameters: 'MyDeviceSource' is the current selected source. 10 frames per trigger using the selected source. '640x480' video data to be logged upon START. Grabbing first of every 1 frame(s). Log data to 'memory' on trigger. Trigger Parameters: 1 'immediate' trigger(s) on START. Status: Waiting for START. 0 frames acquired since starting. 0 frames available for GETDATA.