how to use ToApp block in android support package of simulink?

조회 수: 1 (최근 30일)
Milad Valian
Milad Valian 2016년 7월 9일
댓글: saras 2017년 3월 7일
hello! I don't know how to use ToApp block in simulink. I just know we can use this block to send some data to another application that is written if I'm right. can anyone guide me how to use it? I've read all of the documentations but could not understand. I've written an android code in java. should I use the java code created by simulink in my code or I should do something else?

답변 (2개)

saras
saras 2016년 7월 11일
The ToApp block is used to send data between the host and the generated app. The method that you specify in the block mask will be invoked at every Simulink step. Basically, it provides a way to access data sent by Simulink in your Android app.
Please refer to the example here
Also note that you would need to create this method in java (in the main activity). Your custom java code should be present within this method.
I hope this helps!
  댓글 수: 2
Milad Valian
Milad Valian 2016년 7월 11일
편집: Milad Valian 2016년 7월 11일
thanks for answering. how can I get the java code from simulink?
saras
saras 2016년 7월 11일
When you deploy a Simulink model to your device, an Android project gets created in your working directory. It is this project that will contain the Java code. Please refer to this example to get started.
If you include the ToApp block in your model, you would need to edit the main Activity file, which should be under < model-name>_ert_rtw/< model-name>/src/main/java/com/example/< model-name >/< model-name >.java.
Please note that you can also import this project in an IDE like Android Studio using this guide.

댓글을 달려면 로그인하십시오.


Karl
Karl 2017년 3월 3일
This isn't working as advertised.
I can place the ToApp block in my model, enter the name of my custom method in the block dialog, and it builds and deploys properly - although my method has not yet been defined in the main activity model-name.java
Following the call-chain of the generated code, it would appear that my custom method does indeed need to be placed in this file. But, I would then need to re-build the model so that my custom code is properly included in the app that is deployed.
However, the Simulink build re-generates this file every time that it is invoked - over-writing any changes I make (including the addition of my custom method). The file is not stable, so I can't add code there and have it be included in any subsequent builds.
Do I HAVE to import the generated code to Android Studio in order to fully implement this function? If I add more blocks to the model and have to re-build from Simulink, how can I make the build keep my original custom method?
  댓글 수: 1
saras
saras 2017년 3월 7일
You are correct. You would need to import the project in Android studio to rebuild it with the updated ToApp method. However, rebuilding the model will indeed overwrite the changes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by