Borrar filtros
Borrar filtros

Creating structOfTimeSeries from a bus definition containing 64bit integer type

5 visualizaciones (últimos 30 días)
Hello!
Simulink.SimulationData.createStructOfTimeseries always reporting an error when the bus object contains unsigned 64 bit element.
Error using Simulink.SimulationData.createStructOfTimeseries
Invalid argument for structure timeseries initialization. Element 2 is of type uint64 but the bus object requires type embedded.fi.
Running the following dummy code:
clear
elems(1) = Simulink.BusElement;
elems(1).Name = 'a';
elems(1).DataType = 'uint32';
elems(2) = Simulink.BusElement;
elems(2).Name = 'b';
elems(2).DataType = 'uint64';
TopBus = Simulink.Bus;
TopBus.Elements = elems;
dummyTestStruct = Simulink.Bus.createMATLABStruct('TopBus');
dummyTestStruct.a = timeseries(uint32([0 0 0]), linspace(0,0.1, 3));
dummyTestStruct.a.Data = squeeze(dummyTestStruct.a.Data);
dummyTestStruct.a = setuniformtime(dummyTestStruct.a,'StartTime',0,'EndTime',0.1);
dummyTestStruct.b = timeseries(uint64([0 0 0]), linspace(0,0.1, 3));
dummyTestStruct.b.Data = squeeze(dummyTestStruct.b.Data);
dummyTestStruct.b = setuniformtime(dummyTestStruct.b,'StartTime',0,'EndTime',0.1);
dummyTestTimeSeries = Simulink.SimulationData.createStructOfTimeseries('TopBus',dummyTestStruct);
Thanks
  1 comentario
Nemeth-Nagy David
Nemeth-Nagy David el 24 de Mayo de 2022
need to convert the array to a fi object..
dummyTestStruct.b = timeseries(fi([0 0 0], 0, 64 0), linspace(0, 0.1, 3));
@MathWorks Support Team I think it would worth a comment in the documentation.thanks

Iniciar sesión para comentar.

Respuestas (1)

Riya
Riya el 19 de En. de 2024
Hello Nemeth,
It appears that you're encountering an issue with the `Simulink.SimulationData.createStructOfTimeseries` function when trying to use a `uint64` data type in a bus object. As the error message indicates, Simulink does not support `uint64` data types for timeseries objects.
To work around this limitation, you could consider casting the `uint64` data to a supported data type such as `double` or `embedded.fi` before creating the timeseries, and then cast it back to `uint64` when you need to use the data.
However, keep in mind that if you cast to `double`, you may lose some precision since `double` cannot represent all `uint64` values exactly. If you use `embedded.fi`, you will need the Fixed-Point Designer toolbox.
Here's an example of how you might modify your code to use `embedded.fi` for the timeseries data:
clear
elems(1) = Simulink.BusElement;
elems(1).Name = 'a';
elems(1).DataType = 'uint32';
elems(2) = Simulink.BusElement;
elems(2).Name = 'b';
elems(2).DataType = 'uint64';
TopBus = Simulink.Bus;
TopBus.Elements = elems;
dummyTestStruct = Simulink.Bus.createMATLABStruct('TopBus');
dummyTestStruct.a = timeseries(uint32([0 0 0]), linspace(0,0.1, 3));
dummyTestStruct.a.Data = squeeze(dummyTestStruct.a.Data);
dummyTestStruct.a = setuniformtime(dummyTestStruct.a,'StartTime',0,'EndTime',0.1);
myArray = uint64([0 0 0]); % Example array with uint64 values
wordLength = 64; % Word length for the fixed-point representation
fractionLength = 0; % Fraction length (no fractional part for integers)
% Convert the array to an unsigned fixed-point object with the specified properties
fiObject = fi(myArray, 0, wordLength, fractionLength);
dummyTestStruct.b = timeseries(fiObject, linspace(0, 0.1, 3));
dummyTestStruct.b.Data = squeeze(dummyTestStruct.b.Data);
dummyTestStruct.b = setuniformtime(dummyTestStruct.b,'StartTime',0,'EndTime',0.1);
dummyTestTimeSeries = Simulink.SimulationData.createStructOfTimeseries('TopBus',dummyTestStruct);
Other method could be: If the struct you are passing to this function is correctly formatted to be passed to an input port -
1) Open the Model settings in the Simulink model
2) Go to Data Import/Export
3) Tick the input box and write the name of the uint64 that you want to import to your Simulink model
4) Add an input port into the model which will read this uint64 data. Note- The input port block is the only block in Simulink that supports uint64 datatypes
For more information you can refer following articles for more information:

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by