About legacy code: can you go from labview to simulink via dlls?

16 views (last 30 days)
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!

Answers (1)

Mark McBroom
Mark McBroom on 2 Nov 2024 at 20:38
  2 Comments
Julio Magro
Julio Magro on 11 Nov 2024 at 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
Mark McBroom on 11 Nov 2024 at 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)

Sign in to comment.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!