Open ghost opened 7 years ago
do you used a released version or master? I just rewote that part in master. Can you test?
I do not think it will fix it anyway. I am not sure what is happening here. Are you following the procesdure in examples/server-custom-object.py ? mayne you are writting bad data using set_value(), we do not do any type check on server side...
I used a released version. Using the master I got the following Traceback:
Exception raised while parsing message from client, closing
Traceback (most recent call last):
...
File "...\python-opcua\opcua\ua\uatypes.py", line 1172, in extensionobject_to_binary
TypeId = extension_object_ids[obj.__class__.__name__]
KeyError: 'Prio'
The method _setvalue(value) is called with an enum Prio.Prio3. Thank you for your support!
Enums in ua are not really enum, they are strings. Write a string there.
Maybe we should see if it is possible to raise a more understandable error for users
Thank you very much! Now it works. Maybe it would be helpful to document the usage of enums and other special datatypes.
Hi guys, Little bit late for the discussion but I notice a few things:
1. @oroulet Can you explain what you mean with are enum are strings ?
Enums are coded over the wire as numbers (see Standard Part 6 5.2.3). The set and get of an enum is by this always an Int32. The EnumStrings are only used to make it more human to read/write, but are not required to get stuff working. Due this I doubt if de common test test_enum implementation is correct; I don't expect get_value to return an localized string.
2. @devel0peris Concerning custom types try keep away from namespace 0 in code. python-opcua treat stuff in namespace different.
In xml it is fine if you have a namespace declaration on top like, then on import al your definitions are remapped to the a new namespace index:
<NamespaceUris>
<Uri>http://www.yournamespace.nl/blabla</Uri>
</NamespaceUris>
3. @devel0peris If you apply the above to your enum value xml file the value should be changed to:
<Value>
<uax:Int32>2</uax:Int32>
</Value>
By off course by joining after the discussion it can happen that I totally on the wrong track ;-)
@bitkeeper I do not remember the details but there are two types of enum EnumStrings and EnumValues. one is a string, the other an extension object. The second type might be instanciated as uint32..
@oroulet
EnumStrings and EnumValues are both coded as Int32 (see Standard Part 6 5.2.3). Compare it with enums in C. Take a look at uaprotocol_auto.py
it contains examples of both for example ApplicationType vs AttributeWriteMask.
Think about what it would mean to use LocalizedText as values for clients ...
EnumStrings and EnumValues are only used giving a specific meaning to Int32 value by using label. And has nothing todo with the value transport itself.
The difference between EnumStrings and EnumValues is that EnumString is a fixed sequence and EnumValues allow gaps.
EnumStrings Example:
EnumValues Example:
EnumStrings can just be described as a list because it a sequence (no gaps in the numbers). That is why EnumValues are using a struct (extension object) to describe the relation between the Int32 number and the label.
Attached is a zip that contains a xml schema example for EnumStrings and EnumValues: ua_xmlschema_enumexample.zip
@bitkeeper Interresting. What you say make sense. Do we have en error in implementation? I kind of remember having to write string to enums, but maybe I remember wrong....
@oroulet ok did some enum testsing today, conclusie at the end:
Created opc xml schema with:
Test 1 - load xml schema and inspect the server
Ok: everything seems fine
Test 2 - change value of enum at server side
Nok: No label more present with the value
Expected wrong type due no type check at the server side. Indeed wrong type: Int64
Ok: fine now type ok and label keeps present.
Test 3 - Use value based on IntEnum (like in uaprotocol_auto.py)
Nok: The IntEnum also maps to Int64 instead of Int32
Test 4 - browse existing type I
Ok
Test 5 - browse existing type II
Nok: raise UaError("{0} could not be packed with value {1}".format(vtype, value))
The part that isn't going well is:
standard_address_space_part8.py:953 attrs.Value = ua.Variant(['Linear', 'Log', 'Ln'], ua.VariantType.LocalizedText)
Reproducable by:
v=ua.Variant(['Linear', 'Log', 'Ln'], ua.VariantType.LocalizedText)
v.to_binary()
or even more simple:
v=ua.Variant('Linear', ua.VariantType.LocalizedText)
v.to_binary()
Preliminary Conclusion:
@oroulet
I also have doubts about the implementation ua_utils.py:data_type_to_variant_type
regarding a enumeration.
If now returns ua.VariantType.LocalizedText
or ua.VariantType.ExtensionObject
. I think it should be ua.VariantType.UInt32
?
I got a crash there on an enum last week so you are probably right
On Tue, Apr 25, 2017, 15:50 Marcel notifications@github.com wrote:
@oroulet https://github.com/oroulet I also have doubts about the implementation ua_utils.py:data_type_to_variant_type regarding a enumeration. If now returns ua.VariantType.LocalizedText or ua.VariantType.ExtensionObject. I think it should be ua.VariantType.UInt32 ?
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/FreeOpcUa/python-opcua/issues/426#issuecomment-297036191, or mute the thread https://github.com/notifications/unsubscribe-auth/ACcfzp6mbS8sZlCuMd9oDd1TyxK3KsbLks5rzfofgaJpZM4Mxij4 .
If you have 2 minutes, the best would be to write a small test showing the error
On Tue, Apr 25, 2017, 15:52 Olivier Roulet-Dubonnet < olivier.roulet@gmail.com> wrote:
I got a crash there on an enum last week so you are probably right
On Tue, Apr 25, 2017, 15:50 Marcel notifications@github.com wrote:
@oroulet https://github.com/oroulet I also have doubts about the implementation ua_utils.py:data_type_to_variant_type regarding a enumeration. If now returns ua.VariantType.LocalizedText or ua.VariantType.ExtensionObject. I think it should be ua.VariantType.UInt32 ?
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/FreeOpcUa/python-opcua/issues/426#issuecomment-297036191, or mute the thread https://github.com/notifications/unsubscribe-auth/ACcfzp6mbS8sZlCuMd9oDd1TyxK3KsbLks5rzfofgaJpZM4Mxij4 .
Haha decent tests in 2 minutes ... I will see if I find some time tomorrow.
@bitkeeper I went to all you comment above and I could not see any error.
@oroulet I don't have a problem with set_value at all, it was only a warning that with enums you shouldn't set_value with the default numbers, but explicit use use a Int32 else you end up with Int64.
I think we have 3 things that requires fixing:
ua.Variant('Linear', ua.VariantType.LocalizedText)
is wrong what is correct ?Can we just replace it by ua.LocalizedText('Linear')?
In that case the code generator should be updated.On Tue, Apr 25, 2017, 22:12 Marcel notifications@github.com wrote:
@oroulet https://github.com/oroulet I don't have a problem with set_value at all, it was only a warning that with enums you shouldn't set_value with the default numbers, but explicit use use a Int32 else you end up with Int64.
I think we have 3 things that requires fixing:
- ua_utils.py:data_type_to_variant_type (already fixed see PR #439 https://github.com/FreeOpcUa/python-opcua/pull/439 )
- Using generated classes in uaprotocol_auto.py based on IntEnum as values result in Int64 instead of Int32.
- All the construction like ua.Variant(['Linear', ...], ua.VariantType.LocalizedText) in standard_address_space_part8 will give an exception when a client tries to get the enum labels. You can say it is wrong, but it is the generated code in the standard adress space that uses this construction. If ua.Variant('Linear', ua.VariantType.LocalizedText) is wrong what is correct ?Can we just replace it by ua.LocalizedText('Linear')? In that case the code generator should be updated.
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/FreeOpcUa/python-opcua/issues/426#issuecomment-297150840, or mute the thread https://github.com/notifications/unsubscribe-auth/ACcfzmlmv2Nf2EKFH5Y3Cqr8bGN1Tndgks5rzlOygaJpZM4Mxij4 .
Hey there. I import the following XML into my server:
I add the python object with the following code:
Everything works fine, but when I try to read the custom enum value prio the server crashes:
Can someone please tell me the fault?