Reading a variable gives an error "fmi2getReal is not allowed"

Issue #115 closed
Marek Paty created an issue

Hi,

I am having trouble with reading some variables from an FMU, using fmi-wrapper 2.26.5. Curiously, I can write in the variable (I have checked that the status is OK), but I can’t read it. This happens only for input variables of a particular FMU, whereas the output variables and parameters can be accessed without issue. For some other FMUs, this problem does not arise for any variables. The FMU itself does not seem to be faulty, though, as it can be run for example in Simulink without any problems.

The error I am getting is the following:

fmi2getReal is not allowed for value reference 56.
Exception in thread "main" java.lang.RuntimeException: There was an error getting a variable inside the FMU
at org.javafmi.proxy.v2.Fmu.getReal(Fmu.java:130)
at org.javafmi.proxy.v2.FmuProxy.getReal(FmuProxy.java:165)
at org.javafmi.wrapper.variables.SingleRead.asDouble(SingleRead.java:37)
at RunFMU_Standalone_v1.main(RunFMU_Standalone_v1.java:11)

The code is basically reused from wiki:

import org.javafmi.wrapper.*;

public class RunFMU_Standalone_v1 {
    public static void main(String[] args) {
        System.out.println("Started...");

        Simulation simulation = new Simulation("ClCcFMU.fmu");
        simulation.init(0,1);

        simulation.write("Rte_Sens_PP_Sens_PTO_UIF2_Sens_tSensRaw_VW").with(0.1);
        double value = simulation.read("Rte_Sens_PP_Sens_PTO_UIF2_Sens_tSensRaw_VW").asDouble();
        System.out.println(value);

        System.out.println("Exiting...");
    }   
}

I have been wondering whether the issue might be in the way I built the javaFMI, simpleXML and JNA libraries. I simply downloaded the jar files, extracted them and added the directories to classpath. On the other hand, I didn’t come across any other issues when using the fmi-wrapper, so the libraries seem to work correctly.

Unfortunately, I can’t share the FMU due to confidentiality. I understand that this limits severely your chances for resolving the issue.

Kind regards,

Marek

Comments (5)

  1. Jose Evora

    Hi Marek,

    As you mention it is very difficult to investigate the issue without having the FMU or at least the code you inserted in the framework. Maybe you can build a minimal case in which the error exists that is not confidential.

    As a hint, I would follow the trace of the value reference 56. Have you checked how is it defined in the model description? maybe it is not a real but an int?

    Best,

  2. Marek Paty reporter

    Hi Jose,

    thank you for your quick response. I have found that the issue was due to a bug in the FMU. Please consider this matter closed.

    Kind regards,

    Marek

  3. Log in to comment