FreeOpcUa / opcua-asyncio

OPC UA library for python >= 3.7
GNU Lesser General Public License v3.0
1.14k stars 363 forks source link

Creating a server with OPC 40077 fails, due to importer errors #655

Closed GoetzGoerisch closed 1 year ago

GoetzGoerisch commented 3 years ago

Describe the bug
While importing the nodeset 40083 GeneralTypes the importer fails with:

Importing companion spec. XML...
('Error no extension class registered ', 'PIDParametersDataType', NodeId(Identifier=3023, NamespaceIndex=7, NodeIdType=<NodeIdType.Numeric: 2>))

As per discussion with @AndreasHeine we might need to create structs on the fly, while importing.

To Reproduce
Steps to reproduce the behavior incl code: Implement server as per: https://github.com/umati/Sample-Server-asyncio/pull/40 with logging.basicConfig(level=logging.DEBUG)

Expected behavior
The the companion spec is imported and instanciated correctly.

Screenshots
The PR above.

Version
Python-Version: 3.9
opcua-asyncio Version (e.g. master branch, 0.9): 0.9.90

KUZJurk commented 2 years ago

For me the Error is still present when trying to import on sync or on async server. I attached a log file to this post for the importing procedure.

Version

Python-Version: 3.7.9

opcua-asyncio Version: _0.9.92

GeneralTypes_Errorlog.txt _

swamper123 commented 2 years ago

This issue is still up-to-date:

Exception: ('Error no extension class registered ', 'PIDParametersDataType', NodeId(Identifier=3023, NamespaceIndex=4, NodeIdType=<NodeIdType.Numeric: 2>))

This DataType was not added to the extension_objects_by_typeid while importing, which .

Do you have any clue what could be the cause @oroulet ?

schroeder- commented 2 years ago

@swamper123 maybe this recent patch helps here: #947.

GoetzGoerisch commented 2 years ago

Thank you @schroeder- Tried with the latest commit: https://github.com/umati/Sample-Server-asyncio/pull/40/commits/f8da71ec2e6e823aef4222832aee3724f59422a5

Still no luck.

WARNING:asyncua.common.xmlimporter:failure adding node NodeData(nodeid:NodeId(Identifier=6318, NamespaceIndex=8, NodeIdType=<NodeIdType.Numeric: 2>)) maximum recursion depth exceeded while calling a Python object
WARNING:asyncua.common.xmlimporter:Model is missing: http://opcfoundation.org/UA/PlasticsRubber/GeneralTypes/ - Version: 1.03.01 - PublicationDate: 2022-07-13T00:00:00Z or newer
Traceback (most recent call last):
  File "/src/server.py", line 300, in <module>
Start setup...
Setup done! 1.9531893730163574s
Importing companion spec. XML...

UpdateBehavior = ua.UInt32

Handle = ua.UInt32

maximum recursion depth exceeded while calling a Python object
Server doesn't satisfy required XML-Models. Import them first!
    asyncio.run(main())
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/src/server.py", line 137, in main
    pr_imm2mes_idx = await server.get_namespace_index("http://opcfoundation.org/UA/PlasticsRubber/IMM2MES/")
  File "/src/asyncua/asyncua/server/server.py", line 499, in get_namespace_index
    return uries.index(uri)
ValueError: 'http://opcfoundation.org/UA/PlasticsRubber/IMM2MES/' is not in list
schroeder- commented 2 years ago

You have to to add the parameter: strict_mode=False

So this should be the call:

await server.import_xml(os.path.join(BASE_DIR, "nodeset", "Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.xml"), strict_mode=False)

Then all errors are converted to warnings. Maybe this helps to load the nodeset until we fix the underlying issue.

GoetzGoerisch commented 2 years ago

Thank you @schroeder- It works a bit further, at least it starts to import 40077 but throws a lot of Error due to ExtensionObjects. Still does not start the server.

schroeder- commented 2 years ago

I checked it and found the following:

  1. ExtensionObjects: the xml endcoding is only a stub that works for basic types. So there are some errors that needs to be tracked down.
  2. Fields in DataTypes with no DataType pr: #1008
  3. DefaultBinary and DefaultXML nodes without ParentNodeId for example ns=1;i=5038. Don't know if this is a error in the nodeset , because every Variable node should have a ParentNodeId.

This modified nodeset loads: Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.txt

GoetzGoerisch commented 2 years ago

Thanks @schroeder- still don't work for me. See above. Now the max recursion depth is exceeded. e2c1f39

schroeder- commented 1 year ago

With #1259 everything works without any changes or strict_mode=False

GoetzGoerisch commented 1 year ago

Can confirm from my side: https://github.com/umati/Sample-Server-asyncio/commit/b257fb489ecc757c344f994083f4526102a80c50