Instantiating an Adaptor Object
Every adaptor must include a createInstance()
function. The engine
calls this function to instantiate an object of your adaptor's class. This section includes
the following topics:
Suggested Algorithm
The algorithm for the createInstance()
function is simple: call
the adaptor class constructor to instantiate an object of an adaptor class and return a
handle to the object. The engine passes these arguments to your adaptor's
createInstance()
function. The createInstance()
function accepts three arguments:
imaqkit::IAdaptor* createInstance(imaqkit::IEngine* engine, imaqkit::DeviceInfo* deviceInfo, const char* FormatName)
The following table describes these arguments. Your adaptor's
createInstance()
function must return a handle to an
IAdaptor
object.
Argument | Purpose |
---|---|
| Handle to an |
| Handle to an |
| A character vector that specifies the name of a video format
supported by the device or the full path of a device configuration
file. If this specifies a format, it must be one of the formats
represented by the |
Implementing Your Adaptor Class Constructor
Because you write the code that calls your adaptor class constructor, you can define
the arguments accepted by your adaptor class constructor. At a minimum, adaptor
constructors must accept a handle to an IEngine
object that
represents the connection between the engine and your adaptor. This is defined by the
IAdaptor
superclass. Your adaptor uses this handle to access
engine functions for packaging image frames and returning them to the engine.
In addition to this required argument, many adaptors also accept two other arguments
Handle to an
IDeviceInfo
object that specifies the device to which you want to connectCharacter vector specifying the desired acquisition source format or the full path to a device configuration file (also known as a camera file)
These are the same arguments passed to your adaptor's
createInstance()
function.
Suggested Algorithm
The requirements of your image acquisition device will determine what your class constructor must do. Class constructors typically perform tasks that only need to be performed once by the class, such as
Setting up listeners for all device-specific properties. Listeners notify the class when a user changes the value of a device-specific property. See Implementing Get and Set Support for Device-Specific Properties.
Creating a critical section object. Your adaptor will use the critical section to protect data members that might be accessed from multiple threads. See Using Critical Sections.
Note
Your class constructor should not perform any device initialization, because a user might want to create multiple video input objects. Device initialization occurs when a user has requested frames — see Opening and Closing Connection with a Device.
Example
The following example shows a createInstance()
function that
instantiates an object of class MyDeviceAdaptor
.
imaqkit::IAdaptor* createInstance(imaqkit::IEngine* engine, imaqkit::IDeviceInfo* deviceInfo, char* formatName) { // Instantiate an object of your IAdaptor-derived class imaqkit::IAdaptor* adaptor = new MyDeviceAdaptor(engine,deviceInfo,formatName); return adaptor; }
Implementing Your Adaptor Class Destructor
This destructor is invoked whenever the associated video input object in the MATLAB® software is deleted.
delete(vid);
A destructor for a class cannot take parameters or return a value. An adaptor class, as a derived class, must contain a destructor and the destructor must be declared as virtual.
virtual ~MyAdaptor();
Suggested Algorithm
The design of your adaptor class and the requirements of your image acquisition device will determine what tasks your class destructor must perform. Your class must contain a destructor even if it is an empty implementation. Some examples of tasks a destructor might perform include:
Stopping the device, if it is currently acquiring frames — see Suggested Algorithm for stopCapture().
Closing the connection with the device — see Suggested Algorithm for closeDevice().
Deleting the critical section object — see Using Critical Sections.
Example
This example shows a skeletal implementation of a destructor. For a more complete example, see the demo adaptor class.
MyAdaptor::~MyAdaptor(){ }