Search code examples
pythonfmi

How to get String output variables with FMPy?


I'm using FMPy to simulate some FMUs which have String output variables, yet these are not available in the simulation results (object returned by simulate_fmu(filename)).

Are these variables handled in a different way? If so, how can I access them?

Thank you.

Edit 1:

I runned a simulation using values.fmu which has a String output variable (string_out).

Minimal example:

import fmpy
# fmu path
fmu_name = "C:\\fmusdk\\fmu20\\fmu\\cs\\x64\\values.fmu"
# Simulate
res = fmpy.simulate_fmu(fmu_name, stop_time=2., debug_logging=False)
# Results
print('Results names and types: ' + str(res.dtype))

Note: to run the example you have to download and install fmusdk, which requires one of Microsoft Visual Studio 2005 (VS8), 2008 (VS9), 2010 (VS10), 2012 (VS11), 2013 (VS12) or 2015 (VS14).

Output:

Results names and types: [('time', '<f8'), ('int_out', '<i4'), ('bool_out', '?')]

Expected:

I expected that res contained the output variable string_out.

Using debug_logging:

I realised that fmi2GetString is never called, so it wouldn't be possible for the output to have the values of string_out. Because of this I'm not sure if FMPy supports TypeDefinitions String or not.

System details:

Python version: 3.7.3

FMPy version: 0.2.10


Solution

  • Strings are only supported as parameters (as of FMPy 0.2.10). If you need Strings as input or output you can build a custom simulation loop and use the fmu.setString() and fmu.getString() functions directly.

    You can use the custom_input.py example as a starting point.