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

标签 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

我们可以看到,clock_period 的 getter 在 fmi2doStep 之前被正确调用,但在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

有人知道为什么它似乎不受支持吗?或者是否计划得到支持?有什么技巧可以让它发挥作用吗?

谢谢

最佳答案

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

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

关于python - 使用 pyFMI 获取/设置 FMU 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35460453/

相关文章:

python - 无法安装 Kivy : Cython/GCC error

python - Tornado 协程在 Cython 中不起作用

modelica - 交换 Modelica FMU 模型

modelica - 大型模型和用于模型交换的 FMU

simulation - 功能样机接口(interface) (FMI) : Loose vs. 强耦合

python - 从 Python 中的数据帧创建正则表达式匹配列表,然后计算匹配数

python - 打开文件对话框后无法写入 tkinter spinbox

python - cython 中奇怪的整数行为

python - 通过 Cython(回调)将 Python 函数应用于 std::vector

python - 如何使用 Raspbian 保持与蓝牙设备的连接