gusucode.com > target工具箱matlab源码程序 > target/foundation/blks/mex/virtualinport.m
function virtualinport(block) % VIRTUALINPORT describes the virtual input port block % Copyright 2006-2011 The MathWorks, Inc. % $Date: % Parameters: % - Output signal name % - Sampling time % - Output dimensions % - Frame or sample based % - Output data type %% The setup method is used to setup the basic attributes of the % S-function such as ports, parameters, etc. Do not add any other % calls to the main body of the function. setup(block); %% Function: setup =================================================== % Abstract: % Set up the S-function block's basic characteristics such as: % - Input ports, Output ports, Dialog parameters, Options % % C-Mex S-function counterpart: mdlInitializeSizes function setup(block) %% Register number of ports block.NumInputPorts = 0; block.NumOutputPorts = 1; %% Register parameters block.NumDialogPrms = 5; %% Set tunability - one for each dialog parameter block.DialogPrmsTunable = {... 'Nontunable', 'Nontunable', 'Nontunable', 'Nontunable', 'Nontunable' }; %% Override output port properties block.OutputPort(1).DatatypeID = getOutputDataType(block); block.OutputPort(1).Complexity = 'Real'; dims = block.DialogPrm(3).Data; if isempty(dims)||~strcmp(class(dims), 'double')||~isvector(dims)||(numel(dims)>2) DAStudio.error('TARGETFOUNDATION:blocks:virtualInportOutputMustBe1x2'); end block.OutputPort(1).Dimensions = [dims(1) dims(2)]; isframe = block.DialogPrm(4).Data; if isframe block.OutputPort(1).SamplingMode = 'Frame'; else block.OutputPort(1).SamplingMode = 'Sample'; end %% %% ----------------------------------------------------------------- %% Register sample times %% [0 offset] : Continuous sample time %% [positive_num offset] : Discrete sample time %% %% [-1, 0] : Port-based sample time %% [-2, 0] : Variable sample time %% ----------------------------------------------------------------- %% For a non-frame, just output each matrix at the indicated "per %% message" sample time. For a frame, the sample time is "per element", %% and we multiply the sample time by the size of the frame (eg, # of %% rows). %% ----------------------------------------------------------------- ts = block.DialogPrm(2).Data; if ~isempty(ts)&& strcmp(class(ts), 'double') && ((ts == -1) || (ts == Inf) || (ts > 0)) else DAStudio.error('TARGETFOUNDATION:blocks:virtualInportSamplingTime'); end if (ts==-1)||(ts == Inf) block.SampleTimes = [-1 0]; elseif isframe block.SampleTimes = [ts*dims(1) 0]; else block.SampleTimes = [ts 0]; end %% Options % Specify if Accelerator should use TLC or call back into MATLAB file block.SetAccelRunOnTLC(false); %% ----------------------------------------------------------------- %% The MATLAB file S-function uses an internal registry for all %% block methods. You should register all relevant methods %% (optional and required) as illustrated below. You may choose %% any suitable name for the methods and implement these methods %% as local functions within the same file. %% ----------------------------------------------------------------- %% Register methods called during update diagram/compilation block.RegBlockMethod('CheckParameters', @CheckPrms); block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup); %% Register methods called at run-time block.RegBlockMethod('ProcessParameters', @ProcessPrms); block.RegBlockMethod('Start', @Start); block.RegBlockMethod('Outputs', @Outputs); block.RegBlockMethod('SimStatusChange', @SimStatusChange); block.RegBlockMethod('Terminate', @Terminate); %% ------------------------------------------------------------------- function CheckPrms(block) %Parameter 1: signal name channame = block.DialogPrm(1).Data; if ~strcmp(class(channame), 'char') DAStudio.error('TARGETFOUNDATION:blocks:virtualInportSignalNameMustBeString'); end % Parameter 2: sampling time ts = block.DialogPrm(2).Data; if ~isempty(ts)&& strcmp(class(ts), 'double') && ((ts == -1) || (ts == Inf) || (ts > 0)) else DAStudio.error('TARGETFOUNDATION:blocks:virtualInportSamplingTime'); end % Parameter 3: data dimension dims = block.DialogPrm(3).Data; if isempty(dims)||~strcmp(class(dims), 'double')||~isvector(dims)||(numel(dims)>2) DAStudio.error('TARGETFOUNDATION:blocks:virtualInportOutputMustBe1x2'); end % Parameter 4: is output frame-based? isframe = block.DialogPrm(4).Data; if ~strcmp(class(isframe), 'double') DAStudio.error('TARGETFOUNDATION:blocks:virtualInportInvalidParameterIsFrame'); end % Parameter 5: RTDX data type dtype = block.DialogPrm(5).Data; if ~strcmp(class(dtype), 'double') DAStudio.error('TARGETFOUNDATION:blocks:virtualInportInvalidParameterDataType'); end %% ------------------------------------------------------------------------ function DoPostPropSetup(block) block.NumDworks = 0; %% ------------------------------------------------------------------------ function ProcessPrms(block) block.AutoUpdateRuntimePrms; %% ------------------------------------------------------------------------ function Start(block) %% ------------------------------------------------------------------------ function Outputs(block) %% ------------------------------------------------------------------------ function SimStatusChange(block, s) %% ------------------------------------------------------------------------ function Terminate(block) %% ------------------------------------------------------------------------ function dtype = getOutputDataType(block) dtype = block.DialogPrm(5).Data; % find matching data type alltypes = [0 1 2 3 4 5 6 7 8]; dtype = alltypes(dtype);