gusucode.com > vnt工具箱matlab源码程序 > vnt/vntblks/vntmasks/private/privatevntslconfigcheck.m
function [errMsg paramsStruct] = privatevntslconfigcheck(blockHandleStr, objConstructor) %PRIVATEVNTSLCONFIGCHECK Checks for config block and update parameters. % % [ERRMSG PARAMSSTRUCT] = PRIVATEVNTSLCONFIGCHECK(BLOCKHANDLESTR, OBJCONSTRUCTOR) % does some validation for CAN configuration blocks in the simulink % model. Updates structure information in the return structure, % PARAMSSTRUCT, and error message, ERRMSG, based on simulink model % information and device selected in block, BLOCKHANDLESTR. % % This function is shared between start() call for Replay, Transmit, % Receive and Log blocks in Vehicle Network Toolbox. % SS 03-20-11 % Copyright 2011-2012 The MathWorks, Inc. % Set error message. errMsg = []; % Find the current block. [blockName, parent] = localFindCurrentBlock(blockHandleStr); % Set the block information. paramsStruct.Parent = parent; paramsStruct.BlockName = blockName; paramsStruct.BlockHandle = get_param(blockName, 'Handle'); % Find the corresponding configuration block. [configBlock, params] = privatevntsfcnfindconfig (parent, objConstructor); % Error conditions if (~iscell(configBlock) && (configBlock==-1)) % No device has been selected. errorStrings = privatevntslstring('errorstrings'); % Modify the error message based on block replay or log. if strcmpi(get_param(paramsStruct.BlockHandle, 'FunctionName'), 'svntcanlog') str = 'log from'; elseif strcmpi(get_param(paramsStruct.BlockHandle, 'FunctionName'), 'svntcanreplay') str = 'replay to'; end errMsg = sprintf(errorStrings.NoDeviceSelected, str); return; end if isempty(configBlock) % Error as no config block was found. errorStrings = privatevntslstring('errorstrings'); errMsg = sprintf(errorStrings.NoCCBlocks, get_param(blockName, 'Device'), get_param(blockName, 'Device')); return; end if (length(configBlock)>1) % Error as more than one config block found for same channel. errorStrings = privatevntslstring('errorstrings'); errMsg = sprintf(errorStrings.MultipleCCBlocks, get_param(blockName, 'Device'), get_param(blockName, 'Device')); return; end if isstruct(params) fields = fieldnames(params); for idx = 1:length(fields) paramsStruct.(fields{idx}) = params.(fields{idx}); end end % Need to warn user when attempting silent mode transmits. if ( (strcmpi(get_param(paramsStruct.BlockHandle, 'FunctionName'), 'svntcantransmit')) && (paramsStruct.SilentMode) ) % Show the warning w = warning('off', 'backtrace'); warning(message('vnt:vntblks:silentMode', blockName, get_param( blockName, 'Device' ), configBlock{ 1 })); warning(w); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [blockName, parent] = localFindCurrentBlock(blockHandleStr) % Find the block with the corresponding block handle - block handle is unique % We should either find only one block. blockName = find_system('LookUnderMasks', 'all', 'FollowLinks', 'on', 'BlockHandle', blockHandleStr); blockName = blockName{1}; % Get the parent system. parent = bdroot(blockName); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%