1

I'm on chapter 11 of the official guide to the open62541 library. The html version is here. Before trying anything custom, I just want to try this feature in the most basic way by "compiling" their example xml file into C code, which can then be compiled with the GCC and run as an OPC server. (If you would like to follow along, download the full source code from the main page—the nodeset compiler tool is in there.)

I'm in a Debian-based environment (CLI only). I made a copy of myNS.xml and saved it directly in the path ~/code/open62541-open62541-6249bb2/tools/nodeset_compiler/, which is also my current working directory in this example. I tried to use the nodeset compiler with exactly the same command that they use in the tutorial: python ./nodeset_compiler.py --types-array=UA_TYPES --existing ../../deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml --xml myNS.xml myNS

The error message I got is this:

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

Any idea what I might be doing wrong?

UPDATE:

Alright, I found out there was a problem with my Opc.Ua.NodeSet2.xml file, which I corrected. If you are following along and would like to grab the version of the file I have, you can get it here.

But now I have this issue:

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:

I tried doing the same thing on my Windows laptop, and here is the error I got:

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                '

1 Answers1

0

The complete documentation for the open62541 nodeset compiler can be found here:

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

The command you are using also seems to be fine.

The last issue you are describing invalid literal for int() is due to a newline inside the value tag of a variable.

This will be fixed with https://github.com/open62541/open62541/pull/2768

For a workaround you can change your .xml from

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

to (no newline):

<Value>            
    <Int32></Int32>
</Value>
Stefan Profanter
  • 6,458
  • 6
  • 41
  • 73
  • I actually tried going through and removing newlines as you suggested but I ended up with the same error. It's possible I missed some, but I tried to be careful. What actually helped was changing line 330 from ```self.value = int(unicode(xmlvalue.firstChild.data))``` to ```self.value = int(unicode(xmlvalue.firstChild.data)) if unicode(xmlvalue.firstChild.data.strip()) else None```. – user1952534 Jun 05 '19 at 01:01
  • Of course, I don't know if that introduced more errors. I'm right now trying to figure out how to use that server that runs the objects you generate, which is its own challenge. Running out of time for this OPAS conference I'm attending next week. – user1952534 Jun 05 '19 at 01:04
  • I wanted to reproduce your issue, but you did not provide the myNS.xml file. That's the one where the error comes from. If you provide that, I can debug further into – Stefan Profanter Jun 12 '19 at 16:14
  • Hey, it's been awhile and this project has passed, but in case anyone else is interested in this problem, I think [this](https://mega.nz/#!9dUR1YLb!tSbdu4PfD8N_df9W7EGLV3aBluWs3JypOLN7b8a0maY) was the file I was using. – user1952534 Nov 19 '19 at 22:46