System object not stop on breakpoints in stepImpl block when running simulink

27 次查看(过去 30 天)
I have several breakpoints in the system object files.
The debugger does not stop on the breakpoints in the "stepImpl" part. But they do stop in the parts such as "getOutputDataTypeImpl" or "getOutputSizeImpl" and so on.
I used the "system object-->simulink extension" file and modified it a little bit.
classdef test0_systemObject < matlab.System & matlab.system.mixin.Propagates ...
& matlab.system.mixin.CustomIcon
% Untitled Add summary here
%
% NOTE: When renaming the class name Untitled, the file name
% and constructor name must be updated to use the class name.
%
% This template includes most, but not all, possible properties, attributes,
% and methods that you can implement for a System object in Simulink.
% Public, tunable properties
properties
end
% Public, non-tunable properties
properties(Nontunable)
end
properties(DiscreteState)
end
% Pre-computed constants
properties(Access = private)
output=5;
end
methods
% Constructor
function obj = test0_systemObject(varargin)
% Support name-value pair arguments when constructing object
setProperties(obj,nargin,varargin{:})
end
end
methods(Access = protected)
%% Common functions
function setupImpl(obj)
% Perform one-time calculations, such as computing constants
end
function [y1,y2] = stepImpl(obj,u)
% Implement algorithm. Calculate y as a function of input u and
% discrete states.
obj.output = obj.output+u;
y1 = u;
y2 = obj.output;
end
function resetImpl(obj)
% Initialize / reset discrete-state properties
end
%% Backup/restore functions
% function s = saveObjectImpl(obj)
% % Set properties in structure s to values in object obj
%
% % Set public properties and states
% s = saveObjectImpl@matlab.System(obj);
%
% % Set private and protected properties
% %s.myproperty = obj.myproperty;
% end
%
% function loadObjectImpl(obj,s,wasLocked)
% % Set properties in object obj to values in structure s
%
% % Set private and protected properties
% % obj.myproperty = s.myproperty;
%
% % Set public properties and states
% loadObjectImpl@matlab.System(obj,s,wasLocked);
% end
%% Simulink functions
% function ds = getDiscreteStateImpl(obj)
% % Return structure of properties with DiscreteState attribute
% ds = struct([]);
% end
function flag = isInputSizeMutableImpl(obj,index)
% Return false if input size cannot change
% between calls to the System object
flag = false;
end
function [y1,y2] = getOutputSizeImpl(obj)
% Return size for each output port
y1 = [1 1];
y2 = [1 1];
% Example: inherit size from first input port
% out = propagatedInputSize(obj,1);
end
function [y1,y2] = isOutputFixedSizeImpl(obj)
% Return true for each output port with fixed size
y1 = true;
y2 = true;
end
function [y1,y2]= getOutputDataTypeImpl(obj)
% Return data type for each output port
y1 = "double";
y2 = "double";
end
function [y1,y2] = isOutputComplexImpl(obj)
% Return true for each output port with complex data
y1 = false;
y2 = false;
end
end
end
  1 个评论
shu
shu 2020-12-4
For anyone who may come aross the same problem, refer to the link:
Change the system object from "code generation" to "Interpreted execution", the "stepImpl" part can be debugged now.

请先登录,再进行评论。

回答(1 个)

BhaTTa
BhaTTa 2025-4-22
编辑:BhaTTa 2025-4-22
Hey @shu, if you are just using matlab functions, you can just change the exexution from "code generation" to "Interpreted execution" (as you have answered this in your comment) to hit the breakpoint, but if you are using external C/C++ function you need to do additonal setup for debugging,you can refer to the link below which has the steps:

类别

Help CenterFile Exchange 中查找有关 Create System Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by