How to Implement Legacy Code that can be called both in Simulink and MATLAB?

2 次查看(过去 30 天)
We have a Simulink Coder project we are working on, and I've gotten relatively familiar with using S-Function Builder blocks to copy old legacy code that we have into the S-Function Wrapper code and use it to create code that will get compiled into Simulink. Now we are learning how to create Test Harnesses to validate the performance of our models. One part of the model uses a custom CRC calculator compiled into an S-Function. Since I need the Test Assessment block to verify that the CRC was calculated correctly, I also need the Test Assessment block to be able to call the CRC calculator, but this means the same legacy code has to be executable in the MATLAB environment since it uses the MATLAB action language. Is there some way to call the already-built S-Function from a MATLAB context, or does it have to be built using a different method to be able to be called from both contexts?

回答(1 个)

Eeshan Mitra
Eeshan Mitra 2023-12-28
A Test Assessment or Test Sequence block cannot directly call an S-Function. However, if the S-Function has input and output ports, the Test Sequence/Test Assessment block can be used to drive inputs and read/verify outputs.
One approach is to generate a Simulink Test harness around the S-Function block (See https://www.mathworks.com/help/sltest/gs/create-a-test-harness.html)
Within the harness creation dialog you can choose a checkbox to insert a Test Assessment block to read the output of the harnessed component (the S-Function block) and perform verifications.
  1 个评论
Dana Schwanke
Dana Schwanke 2024-1-2
I know that it can't call a Simulink S-Function, but why not a MATLAB S-Function? If the action language for the Test Sequence/Test Assessment blocks is MATLAB, they should be able to call any MATLAB function, even custom ones defined in .m files, shouldn't they?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Inputs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by