- 'slrealtime': https://www.mathworks.com/help/slrealtime/
- 'getBufferedData': https://www.mathworks.com/help/slrealtime/api/slrealtime.instrument.getbuffereddata.html
- 'test points': https://www.mathworks.com/help/simulink/ug/working-with-test-points.html
- 'Signal Conversion': https://www.mathworks.com/help/simulink/slref/signalconversion.html
Simulink RT Instrument - How to set maximum amount of data received with getBufferedData() and how to stream each signal?
20 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Target Computer Setup についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!