MATLAB Answers

Level 2 S-Function block port sampling mode error

55 views (last 30 days)
When I try to run a model containing Level-2 m-code S-Function block I have created I get the following error:
Level-2 MATLAB S-function 'wrappedGymPyEnvL2Sfcn' in 'test_sfcn/Level-2 MATLAB S-Function1' does not have a 'SetInputPortSamplingMode' method. When a Level-2 MATLAB S-function with multiple output ports has dynamic sampling mode setting for any of its ports, it is necessary to register a 'SetInputPortSamplingMode' method
In this block I set the input port size and one of the output port sizes based on a dialog parameter. My setup function for this block is shown below:
function setup(block)
block.NumDialogPrms = 3;
block.DialogPrmsTunable = { 'Nontunable' ...
, 'Nontunable' ...
, 'Nontunable' ...
};
% Register number of ports
block.NumInputPorts = 1;
block.NumOutputPorts = 2;
% Setup port properties to be inherited or dynamic
% block.SetPreCompInpPortInfoToDynamic;
% block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
% action input
block.InputPort(1).Dimensions = [1, block.DialogPrm(1).Data];
block.InputPort(1).DimensionsMode = 'Fixed';
% block.InputPort(1).Dimensions = [1, 100]; % maximum dimensions
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).DirectFeedthrough = false;
% Override output port properties
% the state values
block.OutputPort(1).Dimensions = [1, block.DialogPrm(2).Data];
block.OutputPort(1).DimensionsMode = 'Fixed';
% block.OutputPort(1).Dimensions = [1, 100]; % maximum dimensions
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
% current reward value
block.OutputPort(2).Dimensions = [1, 1];
block.OutputPort(2).DimensionsMode = 'Fixed';
block.OutputPort(2).DatatypeID = 0; % double
block.OutputPort(2).Complexity = 'Real';
% block.OutputPort(1).SamplingMode = 'Sample';
% block.OutputPort(2).SamplingMode = 'Sample';
% Register sample times
% [0 offset] : Continuous sample time
% [positive_num offset] : Discrete sample time
%
% [-1, 0] : Inherited sample time
% [-2, 0] : Variable sample time
block.SampleTimes = [0 0];
% Specify the block simStateCompliance. The allowed values are:
% 'UnknownSimState', < The default setting; warn and assume DefaultSimState
% 'DefaultSimState', < Same sim state as a built-in block
% 'HasNoSimState', < No sim state
% 'CustomSimState', < Has GetSimState and SetSimState methods
% 'DisallowSimState' < Error out when saving or restoring the model sim state
block.SimStateCompliance = 'DefaultSimState';
% block.SimStateCompliance = 'DisallowSimState';
block.RegBlockMethod('InitializeConditions', @InitializeConditions);
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Update', @Update);
block.RegBlockMethod('Terminate', @Terminate); % Required
%
% SetInputPortSamplingMode:
% Functionality : Check and set input and output port
% attributes and specify whether the port is operating
% in sample-based or frame-based mode
% C MEX counterpart: mdlSetInputPortFrameData.
% (The DSP System Toolbox is required to set a port as frame-based)
%
% block.RegBlockMethod('SetInputPortSamplingMode', @SetInpPortFrameData);
end
No matter what I do I cannot get rid of this error. I tried adding the following SetInputPortSamplingMode function (see the last commented statement in setup:
function SetInpPortFrameData(block, idx, fd)
block.InputPort(idx).SamplingMode = fd;
block.OutputPort(1).SamplingMode = fd;
end
But if I do this, then I get the following error:
'test_sfcn/Level-2 MATLAB S-Function1' has unknown frame status for its output port 2. When all input ports have known frame status, then all output ports must have known frame status
To be honest though, I haven't a clue what this SetInputPortSamplingMode stuff is about, because as far as I can tell, it is not documented anywhere, so I would also welcome a link to documentation if I have missed it.

  0 Comments

Sign in to comment.

Accepted Answer

Zhimin Wang
Zhimin Wang on 3 Sep 2020
function SetInpPortFrameData(block, idx, fd)
block.InputPort(idx).SamplingMode = fd;
block.OutputPort(1).SamplingMode = fd;
block.OutputPort(2).SamplingMode = fd;
end

  0 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!