0

I am using JFMI (https://ptolemy.berkeley.edu/java/jfmi/) to communicate with FMI (in C) from Java.

For the communication, I use existing functions (e.g., simulation.write(inPort.getName()).with((Double) value);).

However, I face two problems:

  • fmuTemplate.c contains global variables for configuring numbers of float, integer, and other variables. However, the configuration does not seem logical to me. For example, if I write that the NUMBER_OF_REALS is 2, and the NUMBER_OF_INTEGERS is 2, I can only use two times write to real/float or two times to integers. If I want to use 4 scalar variables (2 float, 2 int), I need to define NUMBER_OF_REALS 2 and NUMBER_OF_INTEGERS 4. As if the order is incremental.
  • Writting strings from Java to FMI seems to crash the program ("invalidState:fmi2SetString: Illegal call sequence.").

Did you perhaps encounter similar issues? If yes, could you please share your experience?

Best regards and thank you.

xTrmwYs
  • 43
  • 1
  • 9

1 Answers1

1

Isn't JFMI only for FMI 1.0?

Anyway, I would consider using either JavaFMI or FMI4j as these are still actively maintained and available from maven central.

JavaFMI supports FMI 1.0 and 2.0 for Co-simulation and has a more stable API. FMI4j is faster (JNI vs. JNA) and supports FMI 2.0 for Co-Simulation and Model-Exchange.

laht
  • 86
  • 3
  • Thank you. My understanding of the FMU model was actually wrong. The description from the manual helped, and this works with both with the plugin I used, and JavaFMI. – xTrmwYs Sep 12 '18 at 14:08
  • "All variable values of an FMU are identified with a variable handle called “value reference”. The handle is defined in the modelDescription.xml file (as attribute “valueReference” in element “ScalarVariable”). Element “valueReference” might not be unique for all variables. If two or more variables of the same base data type (such as fmi2Real) have the same valueReference, then they have identical values but other parts of the variable definition might be different" – xTrmwYs Sep 12 '18 at 14:09