How do I output a bus object from a constant block in Simulink? Keep encountering errors that I can't figure out...

7 次查看(过去 30 天)
I'm working on a project where I want to use a constant block to output a bus object that will be fed into the bus input port on a bus assignment block. I also want to store this constant data in the model workspace, but the bus object itself comes from a data dictionary.
I currently have the model workspace with my parameter set up like this:
And when I try to Update Diagram, the error that the diagnostic viewer always returns is:
The main thing that confuses me is that I copied this format for outputting a bus from a constant in the model workspace from another model where it works flawlessly. I have checked and double checked that I have it set up the same, yet Simulink does not seem to think that the parameter is actually set as a struct.

采纳的回答

George Pence
George Pence 2018-1-31
I discovered how to correct the error with the advice of a coworker. Essentially when I exported my Simulink parameter object and examined the code, it was labeled as a struct that output the desired bus object, but had none of the actual data information.
Normally, I would think Matlab would already link to the bus object that was specified and output the proper data fields, but apparently it does not.
My code looked like this:
Input = Simulink.Parameter;
saveVarsTmp{1} = struct;
saveVarsTmp{1}.flag = 0;
% No data in between these lines :(
Input.Value = saveVarsTmp{1};
Input.CoderInfo.StorageClass = 'Auto';
Input.CoderInfo.Alias = '';
Input.CoderInfo.Alignment = -1;
Input.CoderInfo.CustomStorageClass = 'Default';
Input.CoderInfo.CustomAttributes.ConcurrentAccess = false;
Input.Description = '';
Input.DataType = 'Bus: platformState_IO';
Input.Min = [];
Input.Max = [];
Input.DocUnits = '';
clear saveVarsTmp;
But the proper format should have been this:
Input = Simulink.Parameter;
saveVarsTmp{1} = struct;
saveVarsTmp{1}.flag = 0;
% -----------------------
saveVarsTmp{1}.data.dataName1= single(0); % single value data
saveVarsTmp{1}.data.dataName2= single(0); % single value data
saveVarsTmp{1}.data.dataName3= single( ...
[0; 0; 0]); % data with dimension of 3
% -----------------------
Input.Value = saveVarsTmp{1};
Input.CoderInfo.StorageClass = 'Auto';
Input.CoderInfo.Alias = '';
Input.CoderInfo.Alignment = -1;
Input.CoderInfo.CustomStorageClass = 'Default';
Input.CoderInfo.CustomAttributes.ConcurrentAccess = false;
Input.Description = '';
Input.DataType = 'Bus: platformState_IO';
Input.Min = [];
Input.Max = [];
Input.DocUnits = '';
clear saveVarsTmp;
After this, I imported the edited .m file back into my model workspace and immediately all errors went away.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by