Getting data from asychronous mex function.
2 ビュー (過去 30 日間)
古いコメントを表示
I am calling a windows function SetWindowsHookEx() which takes in a pointer to a function that gets called asynchronously. I'm currently passing a a function that is in the mex file to the windows function. This works well, but then I want to get that information back to Matlab. The only solution I've seen is to use writing to file, but the information is just a couple of integers, occurring perhaps once every 10 - 50 ms. Any other alternatives?
0 件のコメント
回答 (2 件)
Walter Roberson
2016 年 10 月 6 日
Store the values in a static area and call into a routine that retrieves the values from the static area.
Or mexPutvariable into 'base' or 'global'
4 件のコメント
Walter Roberson
2016 年 10 月 6 日
If you are servicing queued events by a timer, then the timer can call in to a mex routine to retrieve the stored values.
If you were servicing events by callback, then the routine that receives the data can call the callback.
The grey area is around the question of how to get MATLAB to service the event "when it can", where "when it can" is not intended to be "immediately" and might not even be "as soon as MATLAB itself is back in control, taking into account that MATLAB might be calling into BLAS or LINPACK and so might be busy". I get the impression you are looking for something closer to "maybe on the same boundaries as a graphics callback would be serviced"... and even then, the graphics callback boundaries are not always good times for an interrupt, since graphics callbacks are not infrequently in the middle of real-time work that you cannot afford to have delayed indefinitely. I am wondering if you have thought through the circumstances under which you would like the event to occur or not.
One possibility might be if you could signal an event to an event listener. At the moment I do not see a direct way in Mex to do that. Perhaps if you used engEvalString to call notify() ? That might interrupt MATLAB temporarily "now" but would queue an event that could then be serviced by the regular MATLAB event process.
Philip Borghesani
2016 年 10 月 6 日
編集済み: Philip Borghesani
2016 年 10 月 6 日
I believe that calling back into MATLAB from a windows hook with mexCallMatlab or mexEvalString works fine, or has in past versions of MATLAB. No guarantee that it will continue to be safe with future versions of MATLAB. You can then pass the mex function a function handle to execute when needed.
In any case calling a user defined function is no more likely cause problems than manipulating variables with mexPutVariable.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で National Instruments Frame Grabbers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!