首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Open62541教程编译示例xml文件?

如何从Open62541教程编译示例xml文件?
EN

Stack Overflow用户
提问于 2019-05-29 01:49:46
回答 1查看 822关注 0票数 1

我在open62541图书馆官方指南的第11章。html版本是这里。在尝试任何自定义之前,我只想以最基本的方式尝试这个特性,方法是将他们的示例xml文件“编译”成C代码,然后用GCC编译,并作为OPC服务器运行。(如果您想继续下去,请从主页下载完整的源代码-- nodeset编译器工具就在这里。)

我所处的环境是基于Debian的(仅限于CLI)。我复制了一个myNS.xml,并将其直接保存在path myNS.xml中,这也是本例中我当前的工作目录。我尝试使用与教程中使用的命令完全相同的nodeset编译器:python ./nodeset_编译程序.UA TYPES array=UA_TYPES现有的 --xml myNS.xml myNS。

我得到的错误消息是:

代码语言:javascript
复制
Traceback (most recent call last):
  File "./nodeset_compiler.py", line 126, in <module>
    ns.addNodeSet(xmlfile, True, typesArray=getTypesArray(nsCount))
  File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/nodeset.py", line 224, in addNodeSet
    nodesets = dom.parseString(fileContent).getElementsByTagName("UANodeSet")
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1928, in parseString
    return expatbuilder.parseString(string)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 940, in parseString
    return builder.parseString(string)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0

知道我做错了什么吗?

更新:

好的,我发现我的Opc.Ua.NodeSet2.xml文件出现了问题,我对此进行了更正。如果您正在跟踪并想获取我所拥有的文件的版本,您可以获得它这里

但现在我有个问题:

代码语言:javascript
复制
INFO:__main__:Preprocessing (existing) ../../deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
INFO:__main__:Preprocessing myNS.xml
Traceback (most recent call last):
  File "./nodeset_compiler.py", line 178, in <module>
    ns.allocateVariables()
  File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/nodeset.py", line 322, in allocateVariables
    n.allocateValue(self)
  File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/nodes.py", line 291, in allocateValue
    self.value.parseXMLEncoding(self.xmlValueDef, dataTypeNode, self)
  File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 161, in parseXMLEncoding
    val = self.__parseXMLSingleValue(el, parentDataTypeNode, parent)
  File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 281, in __parseXMLSingleValue
    extobj.value.append(extobj.__parseXMLSingleValue(ebodypart, parentDataTypeNode, parent, alias=None, encodingPart=e))
  File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 223, in __parseXMLSingleValue
    alias=alias, encodingPart=enc[1], valueRank=enc[2] if len(enc)>2 else None)
  File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 198, in __parseXMLSingleValue
    t.parseXML(xmlvalue)
  File "/root/code/open62541-open62541-6249bb2/tools/nodeset_compiler/datatypes.py", line 330, in parseXML
    self.value = int(unicode(xmlvalue.firstChild.data))
ValueError: invalid literal for int() with base 10: ''

UPDATE_2:

我尝试在我的Windows笔记本上做同样的事情,下面是我遇到的错误:

代码语言:javascript
复制
INFO:__main__:Preprocessing (existing) ../../deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
INFO:__main__:Preprocessing myNS.xml
Traceback (most recent call last):
  File "./nodeset_compiler.py", line 178, in <module>
    ns.allocateVariables()
  File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\nodeset.py", line 322, in allocateVariables
    n.allocateValue(self)
  File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\nodes.py", line 291, in allocateValue
    self.value.parseXMLEncoding(self.xmlValueDef, dataTypeNode, self)
  File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 161, in parseXMLEncoding
    val = self.__parseXMLSingleValue(el, parentDataTypeNode, parent)
  File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 281, in __parseXMLSingleValue
    extobj.value.append(extobj.__parseXMLSingleValue(ebodypart, parentDataTypeNode, parent, alias=None, encodingPart=e))
  File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 223, in __parseXMLSingleValue
    alias=alias, encodingPart=enc[1], valueRank=enc[2] if len(enc)>2 else None)
  File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 198, in __parseXMLSingleValue
    t.parseXML(xmlvalue)
  File "C:\Users\ekstraaa\Source\open62541\open62541-open62541-6249bb2\tools\nodeset_compiler\datatypes.py", line 330, in parseXML
    self.value = int(unicode(xmlvalue.firstChild.data))
ValueError: invalid literal for int() with base 10: '\n                '
EN

回答 1

Stack Overflow用户

发布于 2019-06-03 06:21:04

有关open62541节点集编译器的完整文档可以在这里找到:

compiler.html

您使用的命令似乎也很好。

您所描述的invalid literal for int()的最后一个问题是由于变量的值标记中有一个换行符。

这将用https://github.com/open62541/open62541/pull/2768修复。

作为解决办法,您可以将.xml更改为

代码语言:javascript
复制
<Value>            
    <Int32>
    </Int32>
</Value>

致(无换行符):

代码语言:javascript
复制
<Value>            
    <Int32></Int32>
</Value>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56352062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档