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!