Filter löschen
Filter löschen

S-Function generation from dll file

44 Ansichten (letzte 30 Tage)
Antonio Niro
Antonio Niro am 28 Feb. 2023
Beantwortet: Sugandhi am 25 Apr. 2023
Hi to everyone, I have a problem that is really it's driving me crazy. Basically I have a Simulink model in which there is only a S-function builder block. My aim is to generate a S-Function starting from a certain C code. In this C code I import some libraries contained in a separate dll file, thai i generate with Visual Studio 2019. If use use the command "dumpbin /EXPORTS" on my dll file, I can see all the functions I need to import. However every time I run my model, Simulink crashes without any error or warning message. It seems like for some reason, I'm trying to point empty or unallowed memory areas when I try to import the functions from my dll, but it shouldn't be the case since (as I said before), I can see those functions in my dll. If I run the project in Visual Studio everything works fine, this problem only occurs in Simulink. I'm using Matlab/Simulink 2021b and I have already set the VS compiler in Matlab.
Thanks in advance for your help,
Antonio.

Antworten (1)

Sugandhi
Sugandhi am 25 Apr. 2023
Hi Antonio Niro,
I understand that you are getting errors when you run the Simulink model in which there is only a S-function builder block and you want to generate S-Function starting from a certain C code by importing some libraries contained in a separate DLL file, but Simulink crashes without any error or warning message.
Here are some potential workarounds that you can try to resolve the issue:
  1. Ensure that the DLL and the S-Function are compatible: Make sure that the DLL you generated from your C code is compatible with Simulink and the S-Function environment. Check that the DLL is compiled with the correct settings and options, such as the correct target architecture (e.g., 32-bit or 64-bit) and calling conventions (e.g., cdecl, stdcall).
  2. Check for any memory-related issues: Double-check your C code to ensure that there are no memory-related issues, such as uninitialized pointers, buffer overflows, or memory leaks, that could potentially cause crashes when the S-Function tries to interact with the DLL. Make sure that all memory allocations and deallocations are done correctly and safely in your C code.
  3. Verify the function signatures: Make sure that the function signatures of the functions you are trying to import from the DLL in your S-Function match exactly with the signatures defined in the DLL. This includes the function name, return type, and input/output argument types and order. Any mismatch in function signatures can lead to memory access errors and crashes.
  4. Check the path to the DLL: Ensure that the path to the DLL file is correctly specified in your S-Function block in Simulink. The path should be absolute or relative to the location of the Simulink model and should point to the correct location of the DLL file.
  5. Check for any MATLAB or Simulink version compatibility issues: Make sure that your MATLAB and Simulink versions are compatible with the Visual Studio compiler you used to generate the DLL. There could be compatibility issues between different versions of MATLAB/Simulink and Visual Studio, which could potentially result in crashes.
  6. Enable logging and debugging: You can enable logging and debugging options in Simulink to gather more information about the crash. You can use the "Verbose" option in the Simulation tab of the Configuration Parameters dialog in Simulink to enable verbose logging and use MATLAB's built-in debugging tools to debug the S-Function code and investigate any potential issues.
By following these steps and ensuring that your DLL, S-Function, and Simulink model are properly configured and compatible, you should be able to resolve the issue and successfully use your C code in Simulink via the S-Function.

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by