如何编译 Open62541 教程中的示例 xml 文件?



我在 open62541 库官方指南的第 11 章。html版本在这里。在尝试任何自定义之前,我只想通过将其示例 xml 文件"编译"为 C 代码以最基本的方式尝试此功能,然后可以使用 GCC 编译并作为 OPC 服务器运行。(如果您想继续操作,请从主页下载完整的源代码 — nodeset 编译器工具就在那里。

我处于基于 Debian 的环境中(仅限 CLI)。我制作了myNS的副本.xml并将其直接保存在路径~/code/open62541-open62541-6249bb2/tools/nodeset_compiler/中,这也是我在本例中当前的工作目录。我尝试使用与本教程中使用的完全相同的命令来使用 nodeset 编译器:python ./nodeset_compiler.py --types-array=UA_TYPES --exist.。/../deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml --xml myNS.xml myNS

我收到的错误消息是这样的:

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文件有问题,我纠正了它。如果您正在关注并想获取我拥有的文件版本,您可以在此处获取。

但是现在我有这个问题:

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笔记本电脑上做同样的事情,这是我得到的错误:

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:UsersekstraaaSourceopen62541open62541-open62541-6249bb2toolsnodeset_compilernodeset.py", line 322, in allocateVariables
n.allocateValue(self)
File "C:UsersekstraaaSourceopen62541open62541-open62541-6249bb2toolsnodeset_compilernodes.py", line 291, in allocateValue
self.value.parseXMLEncoding(self.xmlValueDef, dataTypeNode, self)
File "C:UsersekstraaaSourceopen62541open62541-open62541-6249bb2toolsnodeset_compilerdatatypes.py", line 161, in parseXMLEncoding
val = self.__parseXMLSingleValue(el, parentDataTypeNode, parent)
File "C:UsersekstraaaSourceopen62541open62541-open62541-6249bb2toolsnodeset_compilerdatatypes.py", line 281, in __parseXMLSingleValue
extobj.value.append(extobj.__parseXMLSingleValue(ebodypart, parentDataTypeNode, parent, alias=None, encodingPart=e))
File "C:UsersekstraaaSourceopen62541open62541-open62541-6249bb2toolsnodeset_compilerdatatypes.py", line 223, in __parseXMLSingleValue
alias=alias, encodingPart=enc[1], valueRank=enc[2] if len(enc)>2 else None)
File "C:UsersekstraaaSourceopen62541open62541-open62541-6249bb2toolsnodeset_compilerdatatypes.py", line 198, in __parseXMLSingleValue
t.parseXML(xmlvalue)
File "C:UsersekstraaaSourceopen62541open62541-open62541-6249bb2toolsnodeset_compilerdatatypes.py", line 330, in parseXML
self.value = int(unicode(xmlvalue.firstChild.data))
ValueError: invalid literal for int() with base 10: 'n                '

open62541 nodeset 编译器的完整文档可以在这里找到:

https://open62541.org/doc/current/nodeset_compiler.html

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

invalid literal for int()描述的最后一个问题是由于变量的值标记内的换行符造成的。

这将通过以下方式修复 https://github.com/open62541/open62541/pull/2768

对于解决方法,您可以将.xml从

<Value>            
<Int32>
</Int32>
</Value>

到(无换行符):

<Value>            
<Int32></Int32>
</Value>

最新更新