simulink建模使用bus creator将不同数据类型的信号输出给Outport时,会产生以下报错:
” Input port cannot accept a virtual bus of mixed data types.”
bus creator是虚拟的bus,不支持将不同数据类型的信号输出给Outport。
因此,需要将虚拟bus转化为非虚拟bus(virtual bus to nonvirtual bus),转化方法是将bus creator中的Output data type设置一个自定义的BusObject类型,并且勾选Output as nonvirtual bus,如下图。
自定义的BusObject类型可以手动在base workspace中设置,也可通过脚本来实现,实现的代码放在一个函数中(如下代码),方便使用。具体的需求可以通过修改代码来实现。
function bus()
% BUS initializes a set of bus objects in the MATLAB base workspace
% Bus object: BusObject
clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'a';
elems(1).Dimensions = 1;
elems(1).DimensionsMode = 'Fixed';
elems(1).DataType = 'single';
elems(1).SampleTime = -1;
elems(1).Complexity = 'real';
elems(1).Min = [];
elems(1).Max = [];
elems(1).DocUnits = '';
elems(1).Description = '';
elems(2) = Simulink.BusElement;
elems(2).Name = 'b';
elems(2).Dimensions = 1;
elems(2).DimensionsMode = 'Fixed';
elems(2).DataType = 'uint8';
elems(2).SampleTime = -1;
elems(2).Complexity = 'real';
elems(2).Min = [];
elems(2).Max = [];
elems(2).DocUnits = '';
elems(2).Description = '';
elems(3) = Simulink.BusElement;
elems(3).Name = 'c';
elems(3).Dimensions = 1;
elems(3).DimensionsMode = 'Fixed';
elems(3).DataType = 'uint8';
elems(3).SampleTime = -1;
elems(3).Complexity = 'real';
elems(3).Min = [];
elems(3).Max = [];
elems(3).DocUnits = '';
elems(3).Description = '';
BusObject = Simulink.Bus;
BusObject.HeaderFile = '';
BusObject.Description = '';
BusObject.DataScope = 'Auto';
BusObject.Alignment = -1;
BusObject.Elements = elems;
clear elems;
assignin('base','BusObject', BusObject);
end
通过以上的处理,就可以实现将不同数据类型的信号通过bus creator输出给Outport。
还存在另外一种方法也可实现将不同数据类型的信号通过bus creator输出给Outport,具体实现方法见链接:
https://blog.csdn.net/weixin_47207479/article/details/126384741