Is it possible to call JAVA code from within Simulink?

3 次查看(过去 30 天)
I would like to use Simulink to call, run, or use a JAVA program. I wonder if this can be done using an S-function.

采纳的回答

MathWorks Support Team
There is no direct functionality to call JAVA code from Simulink. One possible workaround is to use an S-function block. The S-function blocks are written in MATLAB, C, C++ or Ada code.
In the attached example, we show how a Level-2 MATLAB S-function block with appropriate block parameters and callbacks setup ; is able to call java code.
A simple Java call example is provided in the attached files wherein a Java String is created and the raw bytes are extracted from it and displayed. The Java Code has been placed in the 'output' callback of the S-Function, so it executes every time an output needs to be produced. Please look into the MATLAB Code of the S-Function block by right-clicking the S-Function block and choosing 'Look Under Mask'. This example has been created by modifying the MATLAB Times Two S-Function example that ships with MATLAB.
Please note that using Java calls with S-function may lead users to believe that it may be possible to do the same in Embedded MATLAB function block. However, this is not advisable because if you need to import any of the Java libraries using the 'IMPORT' function, this can not be done as Embedded MATLAB Fcn Block does not support the IMPORT command.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Block and Blockset Authoring 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by