openmodelicainterest  

Re: bug or wrong usage of external functions

Martin Sjölund
Fri, 22 Jan 2010 08:16:38 -0800

Hi,

It seems this is indeed an OpenModelica bug. The prototype and function call are done properly. But when copied into the result structure, the order is mixed up:

  rv_ext = exttest(omega_ext, Position_ext, &outx_ext, PPP_ext);
  out.targ1 = (modelica_integer)outx_ext;
  out.targ2 = (modelica_integer)rv_ext;

--
Martin Sjölund

Kiel, Dr. Henning wrote:
Hi list,
the Modelica Laguage Spec 3.1 has an example for external function with two output values (one via return other via pointer parameter) in chapter 12.9.5.3. I'm trying to simulate an electronic device which reacts on hall pulses generated by a motor. I implemented a DC-motor in modelica and am calling my "device" (external C function "fexttest") via algorithm: algorithm
    if HallSignal <> pre(HallSignal) then
      (Check, BBR) := fexttest(omega, HallPos, table);
This basically works. Has anyone a better construct? Now to the real problem: I wrote code that should do the same as in the example, but what I see is that the return value and the pointer parameter values are swapped (see plot). In the external function I just return constants to be sure to to know what I return. I would expect the two values to be just the other way round.
Is this a bug, or am I doing something wrong?
I attached all required files.
function fexttest
      input Real omega;
      input Integer Position;
      input demoPack_Data PPP;
      output Integer rv;
      output Integer outx;
external "C" rv = exttest(omega, Position, outx, PPP) annotation(Library="exttest.o",Include="#include \"exttest.h\"");
    end fexttest;
Regards,
Henning

Leopold KOSTAL GmbH & Co. KG - Sitz Lüdenscheid, Registergericht Iserlohn HRA 2854, phG Kostal Verwaltungsgesellschaft mbH, Registergericht Iserlohn HRB 4061 - USt-Id-Nr./Vat No.: DE 125800885

Post- und Werksanschrift: An der Bellmerei 10, D-58513 Lüdenscheid * Telefon: +49 2351 16-0 * Telefax: +49 2351 16-2400 Bellmerei

Geschäftsführung: Dipl.-Kfm. Helmut Kostal (Vorsitzender), Dipl.-Oec. Andreas Kostal, Dipl.-Wirtsch.-Ing. Hermann Eidel, Dipl.-Ing. Marwin Kinzl, Dr.-Ing. Ludger Laufenberg


------------------------------------------------------------------------