- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Newbie question: Openmodelica and FMU...
Newbie question: Openmodelica and FMU export/import
Newbie question: Openmodelica and FMU export/import
Hello,
I am very new to OpenModelica and I want to generate an FMU that will then call my C/C++ functions. I found how to include external C files with my functions, and they are properly called from the model when it runs inside OMD. I am using OMEdit connected to OpenModelica 1.9.0 r17628 as reported in the About box.
The problem starts when exporting my test model to an FMU.
The model is a very simple adaptation of an example which, looks like this:
Code:
class ExternalSin "Test class to redirect to external C functions"
extends ExternalObject;
function constructor
input Real t;
output Real y;
external "C" y = mySin(t) annotation(Include = "#include \"myExternalSin.c\"");
end constructor;
function destructor
external "C" mySinDtor("Hello from Modelica") annotation(Include = "#include \"myExternalSin.c\"");
end destructor;
end ExternalSin;
The external C code is :
Code:
#ifndef _ExternSin_
#define _ExternSin_
#include <ModelicaUtilities.h>
#include <math.h>
double mySin(double x)
{
printf("mySin ctor called with %f\n", x);
return sin(x);
}
void mySinDtor(modelica_string s)
{
const char *p = s;
printf("mySin ctor called with %s\n", p);
}
#endif
Then in use this inside a slightly modified hysteresis model:
Code:
model Hysteresis
import ExternalSin;
Real u;
Boolean y;
equation
// u = Modelica.Math.sin(time);
u = ExternalSin(time);
y = u > 0.5 or pre(y) and u >= (-0.5);
end Hysteresis;
This runs fine inside OMEdit environment. However, after exporting is as an FMU, the dll in the package it does not contain the FMI functions, and importing this FMU anywhere, even in OpenModelica fails with messages indicating the missing FMI C-interface.
What am I missing here?
Thanks in advance
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Newbie question: Openmodelica and FMU...