About legacy code: can you go from labview to simulink via dlls?
23 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I am having a problem here generating dlls from LabView to test models in Simulink.
LabView only generates a .h file in addition to the .dll file (SharedLib.dll). My .h file looks like this (SharedLib.h):
#include "extcode.h"
#pragma pack(push)
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
typedef uint16_t Enum;
#define Enum_Inicio 0
#define Enum_Suma 1
#define Enum_Resta 2
#define Enum_Fin 3
/*!
* DLL_Example
*/
double __cdecl DLL_Example(Enum Enum, double Numero1, double Numero2);
MgErr __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
void __cdecl SetExecuteVIsInPrivateExecutionSystem(Bool32 value);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)
My MATLAB code to generate the Simulink block is this one:
def = legacy_code('initialize');
def.SFunctionName = 'DLL_Example';
def.SourceFiles = {'SharedLib.h'};
def.OutputFcnSpec = 'double DLL_Example(Enum Enum, double Numero1, double Numero2)'; %Ver si fallo enum con int32
def.SourceFiles = {'SharedLib.dll'};
legacy_code('generate_for_sim', def)
legacy_code('slblock_generate', def)
The errors I get are these:
Error using legacycode.LCT/generatesimfiles
Cannot find a valid lhs expression in the function specification (only scalar output can be specified as the return of the function):
--> double DLL_Example(Enum Enum, double Numero1, double Numero2)
Error in legacycode.LCT.legacyCodeImpl
Error in legacy_code (line 103)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Error in dll_example (line 17)
legacy_code('generate_for_sim', def)
Please, if you know how to resolve this issue I would be glad to hear it.
Thank you in advance!
0 Commenti
Risposte (1)
Mark McBroom
il 2 Nov 2024 alle 20:38
Try generating an FMU from your Simulink model and then using that FMU in Labview
https://www.mathworks.com/help/slcompiler/gs/export-simulink-models-to-functional-mock-up-units.html
2 Commenti
Julio Magro
il 11 Nov 2024 alle 5:44
Thank you but this is not what I would like to do. I want to take the path LabView->Simulink and not the other way around.
Mark McBroom
il 11 Nov 2024 alle 10:55
Sorry I misread your question. legacy code tool requires that you use the terms "u", "y" and "d" to help it figure out if an argument in your function prototype is an input, output or state. So, change to this.
'double y1 = DLL_Example(int16 u1, double u2, double u3)
Vedere anche
Categorie
Scopri di più su Programmatic Model Editing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!