python-opcua icon indicating copy to clipboard operation
python-opcua copied to clipboard

call_method passing ExtensionObject argument does not support Bit attribute

Open apisapiaDL opened this issue 4 years ago • 17 comments
trafficstars

Hello! I am trying to develop an OPC UA client using “Free OPC UA” in order to test an OPC UA server with an AutoID Companion Specification (It defines some object types with methods and Data Types).

One of these methods takes as an input a ScanSettings parameter defined in the following way in the bsd file:

image

As you can see, the first two fields define a bitmask that figures out which optional fields are specified in the instance of the structure (in this case just LocationType is optional). When I call such method in the following way, I get this error:

image

and the following disassembly code:

image

So, I am wondering if this kind of structure with optional fields are supported by the library and how could be fixed?

I've also tried passing the custom DataType "AntennaNameIdPair" which does not defines optional fields, and the call method seems to work fine.

Python-Version: 3.8 python-opcua Version): 0.98.13

apisapiaDL avatar Mar 08 '21 11:03 apisapiaDL

please provide a simplyfied example code which reproduces the error!

AndreasHeine avatar Mar 08 '21 11:03 AndreasHeine

Hi! Here you can find my OPC UA Server OPC Server.zip

and here my client Visual Studio solution, the script is pythonOPCUA.py pythonOPCUA.zip

Thank you for your support! Amedeo

apisapiaDL avatar Mar 08 '21 14:03 apisapiaDL

I doubt anyone here is going to grab your entire project and troubleshoot it for you. You need to make a simplified example showing how the Bit attribute isn't working...

zerox1212 avatar Mar 08 '21 15:03 zerox1212

I doubt anyone here is going to grab your entire project and troubleshoot it for you. You need to make a simplified example showing how the Bit attribute isn't working...

The first zip contains just an executable Server with AutoID Companion. The second zip is a very simple client with just 43 lines... (Client script.zip)

Amedeo

apisapiaDL avatar Mar 08 '21 16:03 apisapiaDL

I guess, what apisapiaDL is meaning is:

  • he instanced the autoid companion on the server (as defined by opcua nodeset)
  • the client loads the types from theserver and builds a types dictionary
  • now he needs to call a method on it but arguments is a datatype that uses opc:Bit option fields that FreeOpcua client seems not being able to support, in fact client library seems to work fine with other ExtensionObjects.

So, the question might be: does anybody know whether this library has any issues with Bit attributes in ExtensionObjects or simply there is a specific way to handle them on the client side?

ghost avatar Mar 08 '21 16:03 ghost

i will never ever run a exe from someone i dont know!

i am thinking what the diference is "opc:bit" <-> "opc:boolean" in my opinion "opc:boolean" is the true one^^

AndreasHeine avatar Mar 08 '21 16:03 AndreasHeine

l never ever run a exe from someone i dont know! neither would I!

ghost avatar Mar 08 '21 16:03 ghost

Can you test with opcua-asyncio, sync API? I think optional fields are missing at some places in python-opcua. But this is the old format and it is not supported. try to call load_data_type_definition() and see if your server support newer strcut definition

oroulet avatar Mar 08 '21 17:03 oroulet

I believe I'm having a similar issue. You can try to load up an xml with a type dictionary that includes something like the one i got from an OPC Binary:

<?xml version="1.0" encoding="UTF-8"?>
<opc:TypeDictionary xmlns:opc="http://opcfoundation.org/BinarySchema/" xmlns:tns="http://kistler.com/comoneo" xmlns:ua="http://opcfoundation.org/UA/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" DefaultByteOrder="LittleEndian" TargetNamespace="http://kistler.com/comoneo">
      <opc:StructuredType BaseType="ua:ExtensionObject" Name="ProcessValueType">
            <opc:Field TypeName="opc:Bit" Name="cavityIdSpecified" />
            <opc:Field TypeName="opc:Bit" Name="descriptionSpecified" />
            <opc:Field Length="30" TypeName="opc:Bit" Name="Reserved1" />
            <opc:Field TypeName="opc:CharArray" Name="name" />
            <opc:Field TypeName="opc:Double" Name="value" />
            <opc:Field TypeName="opc:UInt32" Name="assignment" />
            <opc:Field TypeName="opc:UInt32" Name="source" />
            <opc:Field SwitchField="cavityIdSpecified" TypeName="opc:UInt32" Name="cavityId" />
            <opc:Field TypeName="opc:CharArray" Name="id" />
            <opc:Field SwitchField="descriptionSpecified" TypeName="opc:CharArray" Name="description" />
         </opc:StructuredType>
...
</opc:TypeDictionary>

Reconstructing that type with the Bit field will lead to AttributeError: module 'opcua.ua' has no attribute 'Bit'. I worked with this by using test_units.py and changing the file.

Bit implementation here seems somehow relevant but I think I have to read a lot more source code and figure out how to have that included as part of the code generation. Is it some legacy code that we threw away in the past?

deeTEEcee avatar Jan 31 '22 03:01 deeTEEcee

I can't use the newer async library either because that seems to require DataTypeDefinition objects which exist in the server but im working from the client side and have no control over what is on the server. If I use that lib, I just get messages like this one: DEBUG:asyncua.common.structures104:ns=1;g=c2089763-b599-482c-9664-e7fa2fa3b654 has no DataTypeDefinition attribute

deeTEEcee avatar Jan 31 '22 03:01 deeTEEcee

The problem i that optional fields are not implemented in the parsing of xml form the server. Here is the code: https://github.com/FreeOpcUa/opcua-asyncio/blob/master/asyncua/common/structures.py#L137

one should create that "Encoding" dataclass menember if a bit is decclared. Like this: https://github.com/FreeOpcUa/opcua-asyncio/blob/master/asyncua/common/structures.py#L137. than make sure that the field in question is declared as optional later while paring all fields

yo should implement something similar to

oroulet avatar Jan 31 '22 06:01 oroulet

@oroulet thanks, I believe I've resolved this issue so I'll make a PR for it sometime soon.

deeTEEcee avatar Feb 16 '22 19:02 deeTEEcee

are we currently only accepting PR's in the newer async library?

deeTEEcee avatar Feb 16 '22 19:02 deeTEEcee

I can merge anything. But if the bugs exist for both then it would be very nice with a bug fix in asyncua

oroulet avatar Feb 16 '22 19:02 oroulet

ya i can add it in for both libraries.

deeTEEcee avatar Feb 16 '22 23:02 deeTEEcee

it looks like i got some assistance as someone else helped me make the PR for opcua-asyncio: https://github.com/FreeOpcUa/opcua-asyncio/pull/900

deeTEEcee avatar May 23 '22 22:05 deeTEEcee