Simulink RT Instrument - How to set maximum amount of data received with getBufferedData() and how to stream each signal?

20 ビュー (過去 30 日間)
Kaan
Kaan 2025 年 1 月 9 日
編集済み: Shantanu Dixit 2025 年 1 月 20 日 11:28
I use Instrument with buffer mode and simulating random model with Simulink RT.
Here is the code for initializing instrument:
tg = slrealtime('TargetPC1');
removeAllInstruments(tg);
hInst = slrealtime.Instrument('test.mldatx');
hInst.addSignal({'test/constant_block'}, 1);
hInst.addSignal({'test/demux_block'}, 1);
hInst.addSignal({'test/gain_block'}, 1);
hInst.addSignal({'test/from_block'}, 1);
hInst.BufferData = true;
addInstrument(tg, hInst)
and getting datas while RT simulation is running with:
buffer_map = getBufferedData(hInst);
buffer_values = buffer_map.values
1 - Since the buffer only clears when I use getBufferedData(), If I don't use this function for a while, it tooks many seconds to get all the data from buffer, but I only need latest data. Therefore, can I only get latest data and shorten the time or can I decrease the buffer size to shorten the time?
2 - I am adding 4 signals above code, outputs of constant, demux, gain and from blocks, but I can only get gain block's output signal data and I can validate these 3 signals are not added to target instrument by using validate(hInst, 'test') and I can see warnings when I try to add them. I think they are optimized because these blocks is just for a connection, not for a mathematical operation. Is there a way to stream all the signals I have added?
I use Python-MATLAB bridge, so I can't use callback method too.
Thank you for your time,
Kaan

回答 (1 件)

Shantanu Dixit
Shantanu Dixit 2025 年 1 月 20 日 11:16
編集済み: Shantanu Dixit 2025 年 1 月 20 日 11:28
Hi Kaan,
To retrieve the latest data from the buffer and reduce the time spent retrieving large amounts of data, you can regularly call 'getBufferedData()' to avoid the buffer accumulating too much data. This ensures that you only access the latest data without significant delays.
% assuming initialized instrument - instObj
instObj.BufferData = true;
start(tg);
% Retrieve and process buffered data
for i = 1:5
pause(1);
logData = getData(instObj);
% visualize/process data as required
end
stop(tg);
function data = getData(instObj)
myMap = getBufferedData(instObj);
disp('New buffer data available:');
data = myMap.values;
% process data as required
end
Streaming signals issue: https://www.mathworks.com/matlabcentral/answers/773802-why-am-i-unable-to-log-or-stream-signals-when-my-application-is-running-on-hardware-external-mode-a. article outlines workarounds (using 'test signals' and 'signal copy') for when you encounter warnings or issues with streaming signals while the model is running on hardware in Simulink Real-Time. The issue typically arises due to signals being optimized out of the model, preventing them from being streamed or logged.
Additionally you can also refer to the detailed MathWorks documentation on slrealtime and provided functionalities:
Hope this helps!

カテゴリ

Help Center および File ExchangeTarget Computer Setup についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by