이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello All,
I am trying to create a S function in matlab which will read data from a video file and send the frame data via the output port.
The each and every frame information is read using a thread (External framework thread invoked through c++)and the information is sent to in the output pin using mdlOutputs.
The S function I created starts the read thread in mdlStart, but the mdlOutputs is called only after the read thread is stopped. hence mdlOutputs give me only the last frame information for every simulation time step.
I would like to know if it is possible to explicitly invoke mdlOutputs from read thread to receive the each and every frame information.
Thank you very much.
Please suggest if Multithreading is possible with S functions.
Regards Sarfraaz
채택된 답변
Kaustubha Govind
2011년 4월 5일
1 개 추천
mdlOutputs must be invoked by the Simulink engine, because it needs the current SimStruct passed in. It is never advisable to call S-function call-back methods from another callback method.
mdlStart is called only once during model execution (at the beginning), whereas mdlOutputs is called at every time step - it seems like you should really be doing your reading in mdlOutputs directly, and not in mdlStart. Is there a reason you chose your current workflow?
댓글 수: 14
Sarfraaz
2011년 4월 6일
Hello Mr. Govind,
The reading of the frames is done using an external framework invoked from the sfunction. It runs as a separate thread and i need to send the frame information through the output port. Is there a any work around??
i tried copying the simstruct in a global variable and tried to invoke mdlOutputs but it doesn't work. is there any event that could be fired to invoke mdlOutputs explicitly ?
Kaustubha Govind
2011년 4월 6일
I'm sorry, but I still don't understand why you don't call this external framework from mdlOutputs directly. That seems like the right way to go in your case.
Sarfraaz
2011년 4월 6일
Even if i call the external framework from mdlOutputs the external framework will run has a separate thread and extract the frame information. I need to find a way to update the output port from the other thread. so that i get information about all the frames.
Kaustubha Govind
2011년 4월 6일
Is there no way to aggregate the data read by the threads and pass them all together back to the S-function? Note that it is not safe to call any MATLAB API functions (mdlOutputs and any SimStruct-related functions included) from a thread - you must also call them from the main process that spawns the threads.
Sarfraaz
2011년 4월 7일
Thanks for the suggestion. I have synchronized the operation between my thread and MATLAB thread.
I am still stuck in the step where is should terminate the MATLAB thread when my other thread ends before the end of simulation time. IS it possible to call mdlTerminate once my other thread is terminated??
Kaustubha Govind
2011년 4월 7일
You must leave all invocations to S-function callback methods (like mdlTerminate) to the Simulink engine. Could you please elaborate on what you do in this "MATLAB thread"?
Sarfraaz
2011년 4월 7일
Most of the computation is done in my thread. MaATLAB thread only initializes the arrays, starts the other thread and updates the output port.
I want to stop the MATLAB thread once my other thread is terminated. If not the data from the last frame read by my thread is given out as output for every simulation step.
Kaustubha Govind
2011년 4월 7일
So would you like to read all the frames only once and send out multiple frames at every time step? It seems like the right thing to do would be to process one frame at a time (so the last frame read by your thread is the latest one to be processed).
Sarfraaz
2011년 4월 8일
I need to process one frame at a time, but I want to stop the simulation once end of video file is reached.
Sarfraaz
2011년 4월 8일
It would also be nice if you tell me how to handle simulink pause in Sfunction
Kaustubha Govind
2011년 4월 8일
I don't know of a way to stop the simulation from the S-function directly, but you can use the Stop Simulation block (http://www.mathworks.com/help/toolbox/simulink/slref/stopsimulation.html) in your model to do this. You can output a non-zero valued signal from the S-function when you want to stop the simulation and connect that signal to the Stop Simulation block. HTH!
Sarfraaz
2011년 4월 8일
Thank you very much. How to handle pause? I dont see any callback function for pause.
Kaustubha Govind
2011년 4월 8일
The above doc page has a link titled "Creating Pause Blocks": http://www.mathworks.com/help/toolbox/simulink/ug/f11-31373.html#bq0ht63
Sarfraaz
2011년 4월 11일
Thank you very much.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Simulink Coder에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
