User`s guide

3 Providing Hardware Information
3-14
Example: Providing Device and Format Information
The following example presents a simple implementation of a getAvailHW()
function that specifies information for one device with two formats. The intent of
this example is to show how you create the objects necessary to store device and
format information. If you add this code to the mydeviceimaq adaptor, you can run
imaqhwinfo('mydeviceimaq') to view the device information.
1
Replace the stub implementation of the getAvailHW() function, created in
“Creating a Stub Adaptor” on page 3-4, with this code:
void getAvailHW(imaqkit::IHardwareInfo* hardwareInfo)
{
// Create a Device Info object.
imaqkit::IDeviceInfo* deviceInfo =
hardwareInfo->createDeviceInfo(1,"MyDevice");
// Create a Device Format object.
imaqkit::IDeviceFormat* deviceFormat =
deviceInfo->createDeviceFormat(1,"RS170");
// Add the format object to the Device object.
// Specifying "true' makes this format the default format.
deviceInfo->addDeviceFormat(deviceFormat, true);
// Create a second Device Format object.
imaqkit::IDeviceFormat* deviceFormat2 =
deviceInfo->createDeviceFormat(2,"PAL");
// Add the second format object to the Device object.
deviceInfo->addDeviceFormat(deviceFormat2, false);
// Add the device object to the hardware info object.
hardwareInfo->addDevice(deviceInfo);
}
2
Rebuild the mydeviceimaq project to create a new DLL.
3
Start the MATLAB software and run the imaqhwinfo function, specifying the
adaptor name mydeviceimaq as an argument. Note how the DeviceIDs field and
the DeviceInfo field of the structure returned by imaqhwinfo now contain data.
dev = imaqhwinfo('mydeviceimaq')