Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » DimitriosNT
  • » Profile

Posts

Posts

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

Feb-28-14 20:15:36
Category: Programming

There is an add-on for Matlab by Modelon. You can find it here:  http://www.modelon.com/products/fmi-toolbox-for-matlab/. It is supposed to enable FMU importing into Simulink.

  • Index
  • » Users
  • » DimitriosNT
  • » Profile
You are here: