Conversation
…ustom objects Added a helper tool to be able to add a custom object type more easily
…to FreeOpcUa-master # Conflicts: # tests/tests_common.py
…orts Added an example that show how to use complex types
| result = func(self, parent, *[arg.Value for arg in args]) | ||
|
|
||
| if isinstance(result, (list, tuple)): | ||
| return to_variant(*result) |
| obj = ExtensionObject() | ||
| obj.TypeId = NodeId.from_binary(data) | ||
| obj.Encoding = uabin.Primitives.UInt8.unpack(data) | ||
| if obj.Encoding & (1 << 0): |
There was a problem hiding this comment.
what is that? you cannot test for the value of Encoding without first unpacking?????
There was a problem hiding this comment.
Good call, I don't event remember removing that. I'm putting it back.
opcua/ua/uautils.py
Outdated
| def register_extension_object(object_factory): | ||
| setattr(ObjectIds, "{}_Encoding_DefaultBinary".format(object_factory.__name__), object_factory.DEFAULT_BINARY) | ||
| ObjectIdNames[object_factory.DEFAULT_BINARY] = object_factory.__name__ | ||
| ExtensionClasses[object_factory.DEFAULT_BINARY] = object_factory |
There was a problem hiding this comment.
we already have a file called ua_utils.py under common. Maybe you could put that method in uatypes.py or ua_prototcol_hans.py
There was a problem hiding this comment.
I'll move it to that file.
tests/tests_common.py
Outdated
| # | ||
| # key_value = uabin.unpack_uatype_array(response[0].VariantType, io.BytesIO(response[0].to_binary())) | ||
| # self.assertEqual(key_value.key, "Key") | ||
| # self.assertEqual(key_value.value, "Value") |
There was a problem hiding this comment.
what is the issue with that test?
There was a problem hiding this comment.
I got this error:
`======================================================================
ERROR: test_decode_custom_object (tests_server.TestServer)
Traceback (most recent call last):
File "C:\Work\doc\Open_SCS\opcua-kev\python-opcua\tests\tests_common.py", line 762, in test_decode_custom_object
key_value = uabin.unpack_uatype_array(response[0].VariantType, io.BytesIO(response[0].to_binary()))
File ".\opcua\ua\ua_binary.py", line 305, in unpack_uatype_array
return [unpack_uatype(vtype, data) for _ in range(length)]
File ".\opcua\ua\ua_binary.py", line 305, in
return [unpack_uatype(vtype, data) for _ in range(length)]
File ".\opcua\ua\ua_binary.py", line 286, in unpack_uatype
return extensionobject_from_binary(data)
File ".\opcua\ua\uaprotocol_auto.py", line 16300, in extensionobject_from_binary
TypeId = NodeId.from_binary(data)
File ".\opcua\ua\uatypes.py", line 410, in from_binary
nid.NodeIdType = NodeIdType(encoding & 0b00111111)
File "C:\Python3\lib\enum.py", line 241, in call
return cls.new(cls, value)
File "C:\Python3\lib\enum.py", line 476, in new
raise ValueError("%r is not a valid %s" % (value, cls.name))
ValueError: 14 is not a valid NodeIdType`
It looks like a configuration error but I'm not sure about how to fix it.
There was a problem hiding this comment.
I just reenabled the tests, Maybe someone will know how to fix it?
tests/tests_common.py
Outdated
| # self.assertEqual(key_value.value, "Value") | ||
|
|
||
|
|
||
| class KeyValuePair(object): |
There was a problem hiding this comment.
would be great to give that class a name like MyCustomStructure. It took me a while to understand that this was just an example
There was a problem hiding this comment.
Noted, I'll change that.
Changed the unittest custom error type so it is easier to know that it's a custom class.
| def register_extension_object(object_factory): | ||
| setattr(ObjectIds, "{}_Encoding_DefaultBinary".format(object_factory.__name__), object_factory.DEFAULT_BINARY) | ||
| ObjectIdNames[object_factory.DEFAULT_BINARY] = object_factory.__name__ | ||
| ExtensionClasses[object_factory.DEFAULT_BINARY] = object_factory |
There was a problem hiding this comment.
I just saw that it won't work if your NamespaceIndex is not 0. I'll see what I can do to change that.
|
#388 is now merged, it does th eground work to make possible what you wanted to do on client side (not server). There is now a method to register new structures. Unfortunately I do not have time currently to work on this, but if someone tries to use it I can help |
|
examples/client_read-custom_structures.py |
|
Note to myself: merge interesting commits from that pr |
No description provided.