User`s guide
Code Generation with VideoDevice System Object
14-15
• Specific MathWorks shared libraries under [MATLABROOT]\bin\<ARCH>\
• MathWorks adaptor libraries under [MATLABROOT]\toolbox\imaq\imaqadaptors
\<ARCH>\ specific to the device selected.
You will need to add the above folders to your system path before running the generated
executable outside of MATLAB.
Usage Rules for System Objects in Generated MATLAB Code
• Assign System objects to persistent variables.
• Global variables are not supported.
• Initialize System objects once by embedding the object handles in an if statement
with a call to isempty( ).
• Call the constructor exactly once for each System object.
• Set arguments to System object constructors as compile-time constants.
• Use the object constructor to set System object properties because you cannot use dot
notation for code generation. You can use the get function to display properties.
• Test your code in simulation before generating code.
The following shows an example of some of these rules.
% Note: System Objects created for Codegen have to be persistent variables.
persistent vid;
% Construct the IMAQ VideoDevice System Object.
if isempty(vid)
% Note: All required parameters must be passed to the System Object at
% the point of construction.
vid = imaq.VideoDevice('winvideo', 1, 'MJPG_320x240', ...
'ROI', [1 1 320 240], ...
'ReturnedColorSpace', 'rgb', ...
'DeviceProperties.Brightness', 130, ...
'DeviceProperties.Sharpness', 220);
end
Limitations on Using System Objects in Generated MATLAB Code
Ensure that the value assigned to a nontunable or public property is a constant and
that there is at most one assignment to that property (including the assignment in the
constructor). Do not set any properties during code generation.