www.gusucode.com > vnt工具箱matlab源码程序 > vnt/vntblks/vntmasks/private/privatecansladdconfig.m

    function privatecansladdconfig(obj, blockType)
%PRIVATECANSLADDCONFIG Checks and adds a CAN configuration block. 
%
%    PRIVATECANSLADDCONFIG(OBJ, BLOCKTYPE) Gives an option to the user to
%    add a CAN configuration block to the model, if none found already
%    with a selected CAN hardware specified in the object, OBJ.
%
%    BLOCKTYPE is a string with values: 'Receive' or 'Transmit'.

%    SS 09-01-08
%    Copyright 2008 The MathWorks, Inc.

% Get the error strings.
strings = privatevntslstring('errorstrings');

% Find the block names with the specific CAN hardware.
blockNames = find_system(bdroot, 'LookUnderMasks', 'all', 'MaskType', 'CAN Configuration', ...
                         'Device', obj.Device);

% Display a message to user if not found.
if isempty(blockNames)
    % Display the question dialog to user.
    question = sprintf(strings.AddCANConfigBlock, blockType);
    userSelection = ...
        questdlg(question, strings.QuestDlgTitle, 'Yes', 'No', 'Yes');
    
    if strcmpi(userSelection, 'Yes') % If user selects Yes.
        block = get(obj, 'Block');
        destination = sprintf('%s/CAN Configuration', block.Path);
        %Find the position to add the block in the model. 
        load_system('canlib'); % Just to ensure the model lib is loaded.
        position = tamslgate('privateslfreespace', 'canlib/CAN Configuration', ...
                                       block.Path);
        % Add the block with the specified Serial port.  
        add_block('canlib/CAN Configuration',destination, ...
                  'MakeNameUnique', 'on', ...
                  'Position', position, ...
                  'DeviceMenu', obj.DeviceMenu, ...
                  'Device', obj.Device, ...
                  'ObjConstructor', obj.ObjConstructor);
    end
end