| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → xPC Target |
| Contents | Index |
| Learn more about xPC Target |
The following is the block mask for the Diamond MM-32 Analog Input block.

If you were to create this mask as a new mask, you would:
Select the Parameters tab and click the Add button on the left three times.
Three blank lines appear in the Dialog parameters section. Fill them in as follows, starting with the first line:
In the Prompt column, enter
Channel configuration
First channel number:
Number of channels:
Range
Sample time:
Base address (for example 0x300):
In the Variable column, enter the parameter names. Be sure that these names match the S-function parameters field of the S-Function block.
configuration
firstChan
numChans
range
sampleTime
base
In the Type column, select:
popup
edit
edit
popup
edit
edit
In the Evaluate and Tunable columns, ensure that the first five check boxes of Evaluate and all the check boxes for Tunable are selected.

Select the Initialization tab. The tab displays the dialog variables you entered in the Parameters tab.
In the Initialization code section, type
phase = 2; [baseDec, maskDisplay, maskDescription] = maddiamondmm32(phase, configuration, firstChan, numChans, range, base); set_param(gcb, 'MaskDescription', maskDescription); set_param(gcb, 'MaskDisplay', maskDisplay);
where maddiamondmm32 references the maddiamondmm32.m file for the driver.
In this M-file, you should check the range values of the parameters. Checking the mask here will catch illegal values early in the build process.
This example returns a string to display on the block with the variable port_label commands with which to label the input and output ports. The number and content of the port_label commands depend on the channel vector that the user enters in the mask.
Select the Documentation tab. This tab contains three fields, Mask type, Mask description, and Mask help.
In the Mask type field, enter the type of driver. For example:
addiamondmm32
In the Mask description field, enter a description for the driver. For example:
MM-32 Diamond Analog Input
In the Mask help field, if you are providing any online documentation to associate with the Help button, you can call that online documentation from this field. See Defining Mask Documentation in the Working with Block Masks chapter of Simulink User's Guide for details.
Click OK to save the mask.
After you create the block mask, you can define an InitFcn callback for the block. A model calls this callback at the start of model simulation.
Right-click the block and select Block Properties from the drop-down list.
Select the Callback tab from the dialog. From the list, select InitFcn. Enter M-code in the edit box.
One convention is to use the same function that is used at mask initialization time (for example, maddiamondmm32.m), but with a single argument that indicates that this is being called at InitFcn time.
maddiamondmm32(1)
At InitFcn time, no variables in the mask exist yet. You cannot pass them into the InitFcn. However, in the function, you can get the string values using the get_param function. For example:
function [baseDec, maskDisplay, maskDescription] = ...
maddiamondmm32(phase, configuration, firstChan, numChans, range, base) %#ok
vendorName = 'Diamond';
deviceName = 'MM-32';
description = 'Analog Input';
maskType = 'addiamondmm32';
if phase ~= 2 % assume InitFcn unless phase 2
base = get_param( gcb, 'base' );
blocks = find_system(bdroot, 'FollowLinks', 'on', ...
'LookUnderMasks', 'all', 'MaskType', maskType, 'base', base);
if length(blocks) > 1
error('xPCTarget:DiamondMM32:Block',...
'Only one Diamond Systems MM-32 A/D block per ...
physical board allowed in a model - each block of ...
this type must have a distinct ISA address.');
end
return
end
![]() | When You Are Done | Interrupt Support | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |