使用pyFMI获取/设置FMU的字符串

时间:2016-02-17 15:10:08

标签: python cython fmi

我正在使用Modelon的pyFMI在systemC和其他工具之间进行协调,比如说openModelica。

我们尝试获取并设置类型字符串的输入但似乎不支持。 我们在description.xml文件中有什么:

<ScalarVariable name="clock_timescale" valueReference="0" description="timescale of the internal clock manager" causality="parameter" variability="fixed" initial="exact">
    <String start ="NS" />
</ScalarVariable>
<ScalarVariable name="clock_period" valueReference="4" description="period of the internal clock manager" causality="parameter" variability="fixed" initial="exact">
    <Integer start ="20" />
</ScalarVariable>

在这个例子中,clock_period是一个整数,clock_timescale是一个字符串。如果我们快速查看pyfmi日志,我们可以看到:

FMIL: module = Model, log level = 4: [logFmiCall][FMU status:OK] 
   fmi2GetInteger: clock_period = 20
FMIL: module = Model, log level = 4: [logFmiCall][FMU status:OK] 
   fmi2GetInteger: number_isready = 0
FMIL: module = Model, log level = 4: [logFmiCall][FMU status:OK] 
   fmi2GetInteger: number_port = 0
FMIL: module = Model, log level = 4: [logFmiCall][FMU status:OK] 
   fmi2GetInteger: result_port = 0
FMIL: module = Model, log level = 4: [logFmiCall][FMU status:OK] 
   fmi2GetInteger: result_isready = 0
FMIL: module = Model, log level = 4: [logFmiCall][FMU status:OK] 
   fmi2GetBoolean: reset = true
FMIL: module = Model, log level = 4: [logFmiCall][FMU status:OK] 
fmi2DoStep: currentCommunicationPoint = 0 communicationStepSize=20, noSetFMUStatePriorToCurrentPoint =1, internal time=0

我们可以看到在fmi2doStep之前正确调用了clock_period的getter,但没有在clock_timescale之前调用。

此外,如果我们尝试设置字符串,我们会收到以下错误:

Traceback (most recent call last):
  File "coordinator.py", line 56, in <module>
    model.set_string([0],['MS'])
  File "fmi.pyx", line 3555, in pyfmi.fmi.FMUModelBase2.set_string (src/pyfmi/fmi.c:31090)
    NotImplementedError

有人知道为什么它似乎不受支持吗?或者如果计划得到支持?有没有办法让它发挥作用?

感谢

1 个答案:

答案 0 :(得分:1)

正如您所见,不支持使用PyFMI(版本&lt; = 2.2)设置和获取字符串,并且不幸的是没有技巧让它工作。

在下一个版本中,它将得到支持。如果使用开发版本(从源代码构建),这些功能已经实现并可用。