【问题标题】:xml - Reading a config file multiple times (for GNU Radio)xml - 多次读取配置文件(用于 GNU Radio)
【发布时间】:2014-08-08 18:59:46
【问题描述】:

我目前正在处理一个 GNU Radio 项目,但我在 xml 部分遇到了问题。

我需要打开一个配置文件并读取它以获取我的 GNU Radio 变量。

现在,我只有允许读取配置文件的内置文件,但只有一次,在 GNU Radio 流程图的开头。当我在 GNU Radio 运行时在配置文件中更改它时,我想刷新我的变量。

这可能是一个特定的问题,因为它暗示了 XML 和 GNU Radio,但我认为即使不了解 GNU Radio 也可以解决。

所以,就是这样:

<block>
    <name>Variable Config1</name>
    <key>variable_config1</key>
    <import>import ConfigParser</import>
    <var_make>self._$(id)_config = ConfigParser.ConfigParser()
self._$(id)_config.read($config_file)
try: $(id) = self._$(id)_config.$(type.get)($section, $option)
except: $(id) = $value
self.$(id) = $(id)</var_make>
    <make></make>
    <callback>self.set_$(id)($value)</callback> 
    <callback>self._$(id)_config = ConfigParser.ConfigParser()
self._$(id)_config.read($config_file)
if not self._$(id)_config.has_section($section):
    self._$(id)_config.add_section($section)
self._$(id)_config.set($section, $option, str($writeback))
self._$(id)_config.write(open($config_file, 'w'))</callback>
    <param>
        <name>Default Value</name>
        <key>value</key>
        <value>0</value>
        <type>$type</type>
    </param>
    <param>
        <name>Type</name>
        <key>type</key>
        <value>real</value>
        <type>enum</type>
        <option>
            <name>Float</name>
            <key>real</key>
            <opt>get:getfloat</opt>
        </option>
        <option>
            <name>Int</name>
            <key>int</key>
            <opt>get:getint</opt>
        </option>
        <option>
            <name>Bool</name>
            <key>bool</key>
            <opt>get:getboolean</opt>
        </option>
        <option>
            <name>String</name>
            <key>string</key>
            <opt>get:get</opt>
        </option>
    </param>
    <param>
        <name>Config File</name>
        <key>config_file</key>
        <value>default</value>
        <type>file_open</type>
    </param>
    <param>
        <name>Section</name>
        <key>section</key>
        <value>main</value>
        <type>string</type>
    </param>
    <param>
        <name>Option</name>
        <key>option</key>
        <value>key</value>
        <type>string</type>
    </param>
    <param>
        <name>WriteBack</name>
        <key>writeback</key>
        <value>None</value>
        <type>raw</type>
    </param>
    <doc>


This block represents a variable that can be read from a config file.

To save the value back into the config file: \
enter the name of another variable into the writeback param. \
When the other variable is changed at runtime, the config file will be re-written.
    </doc>
</block>

说实话,我根本不懂 XML,但我确实需要这样做。

即使我不了解 XML,我在询问之前也做了一些研究,但没有找到任何东西。

【问题讨论】:

    标签: xml gnuradio configuration-files gnuradio-companion


    【解决方案1】:

    您尝试做的事情没有意义。这些 XML 文件在流程图甚至被转换为 python 源代码之前就已经被真正读取,并且与进一步的操作完全无关。从您的 GRC 流程图生成的 GNU Radio python 应用程序与这些 XML 文件无关

    【讨论】:

      【解决方案2】:

      事实上,在 gnuradio 中有一个块可以做到这一点。 因此,如果有人想在流程图运行时使用 python 更改变量,请查找 xmlrpc 块

      【讨论】:

        猜你喜欢
        • 2023-04-01
        • 2019-08-10
        • 1970-01-01
        • 2011-08-31
        • 2020-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多