フィルターのクリア

How to frequently trigger a MEX function as fast as possible?

3 ビュー (過去 30 日間)
tom
tom 2021 年 7 月 1 日
編集済み: tom 2021 年 7 月 1 日
Hi,
first time post. I'm implementing a interprocess communication between Simulink and a WPF application. I'm already using a TCP approach (using Googles GRPC Protocol) to communicate inbetween both. This works very stable, but is obviously not the fastest implementation. For a faster transmission of signal values, I have implemented an adapter to Shared Memory within a custom C (MEX) extentions.
The Problem:
I need to trigger my MEX adapter as often as possible (~15 ms/60Hz). The operation/callback is very fast! It collects the port values from the Runtime object and sends them over to the memory. The MEX adapter needs below 1 ms for 500 signals on my rather "slow" laptop while a simulation runs. In practise I deal with 30 signals, so its a matter of Microseconds for the whole operation! (Performance was measured with the timeit function under load)
In order to do so I have implemented 4 different ways:
  1. Matlab timer in various settings -> Set to 15ms but fires at 100+ms (too slow) . I don't know why...
  2. add_exec_event_listener -> Fast enough, but does not work in Accelerated Mode and on Simulationstate Idle; Requires a Block to listen which overcomplicates everything.
  3. C++ (MEX) Timer in various implementations -> evalAsync seems to slow down. It performs a bit slower than a Matlab timer
  4. Multiple Matlab timer, firing in chain. Works faster than using a single Matlab timer, but I'm still unable to reach 15 ms
Me and my clients are using Matlab 2019b (Windows).
Now, is there anyway I can trigger everything faster under any circumstances? Isn't it possible to invoke on the main thread properly, without any overhead? Why does add_exec_event_listener is so fast, but the timer fails to keep up? I ran out of ideas... :(
Any help is appreciated!

回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by