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

Reading Custom Structure with B&R OPC UA client fails with Error 0x80390000 Bad_DataEncodingUnsupported

Open MaCar37 opened this issue 1 year ago • 3 comments

Describe the bug
I can not read custom structures from an opcua-asyncio Server using a B&R PLC with an OPC UA client. Reading always fails with Error 0x80390000 Bad_DataEncodingUnsupported.

I already contacted the B&R Suppport. B&R claims the Error indicates that the Sever uses an old implementation of the OPCUA standard.

I also tried other OPC UA Servers where my B&R client could read custom structures.

The same problem might be already mentioned inside the Discussion of the older librabry python-opcua here: #1527

To Reproduce
I used the example server-custom-structures-and-enums.py from this repository. For the client I used the OpcUa_Sample from B&R Automation Studio V4.9.6.42.

Version
Python-Version:
Python 3.9.7 opcua-asyncio Version (e.g. master branch, 0.9):
asyncua 1.0.5

MaCar37 avatar Dec 13 '23 13:12 MaCar37

Hi, I have the same issue. Did you manage to find anything?

rempAut avatar Feb 11 '24 21:02 rempAut

what encoding is it?

there where new (1.04) and old (1.03) structures! have you tried both:

    async def load_type_definitions(self, nodes=None):
        """
        Load custom types (custom structures/extension objects) definition from server
        Generate Python classes for custom structures/extension objects defined in server
        These classes will available in ua module
        WARNING: protocol has changed in 1.04. use load_data_type_definitions()
        """
        _logger.warning("Deprecated since spec 1.04, call load_data_type_definitions")
        return await load_type_definitions(self, nodes)

    async def load_data_type_definitions(self, node: Optional[Node] = None, overwrite_existing: bool = False) -> Dict[str, Type]:
        """
        Load custom types (custom structures/extension objects) definition from server
        Generate Python classes for custom structures/extension objects defined in server
        These classes will be available in ua module
        """
        return await load_data_type_definitions(self, node, overwrite_existing=overwrite_existing)

AndreasHeine avatar Feb 11 '24 21:02 AndreasHeine

Allright, so I got it running, but I don't completely understand why.

  • I used the latests Automation Runtime I4.93
  • changed the OPCUA system configuration to use the 1.04 structure structure definitions image
  • declared the structures in Automation Studio
  • used server.import_xml() to import the generated nodeset file with stucture definitions from Automation Studio.

Now here is the part where I would like to ask for some clarification. I was investigating whatever I could find about the Bad_DataEncodingUnsupported. I noticed a difference in nodesets exported from opcua-asyncio and Automation Studio in the encoding nodes (UAObject vs UAObjectType) Is this relevant? I am attaching snippets from the nodeset files.

Nodeset snippet - exported from Automation Studio

   <UADataType NodeId="ns=1;i=101"
                BrowseName="1:parentElementType">
        <DisplayName>parentElementType</DisplayName>
        <Description>parentElementType</Description>
        <References>
            <Reference ReferenceType="HasSubtype"
                       IsForward="false">i=22</Reference>
            <Reference ReferenceType="HasEncoding">ns=1;i=102</Reference>
        </References>
        <Definition Name="1:parentElementType">
            <Field DataType="i=12"
                   Name="ID" />
            <Field DataType="i=6"
                   Name="Length" />
            <Field DataType="i=6"
                   Name="Diameter" />
        </Definition>
    </UADataType>
    <UAObject SymbolicName="DefaultBinary"
              NodeId="ns=1;i=102"
              BrowseName="Default Binary">
        <DisplayName>Default Binary</DisplayName>
        <References>
            <Reference ReferenceType="HasTypeDefinition">i=76</Reference>
            <Reference ReferenceType="HasEncoding"
                       IsForward="false">ns=1;i=101</Reference>
        </References>
    </UAObject>

 Nodeset snippet - python-asyncua server.export()

    <UADataType NodeId="ns=1;i=3"
                BrowseName="1:parentElementType">
        <DisplayName>parentElementType</DisplayName>
        <Description>parentElementType</Description>
        <References>
            <Reference ReferenceType="HasSubtype"
                       IsForward="false">i=22</Reference>
            <Reference ReferenceType="HasEncoding">ns=1;i=4</Reference>
        </References>
        <Definition Name="parentElementType">
            <Field DataType="i=12"
                   Name="ID" />
            <Field DataType="i=6"
                   Name="Length" />
            <Field DataType="i=6"
                   Name="Diameter" />
        </Definition>
    </UADataType>
    <UAObjectType NodeId="ns=1;i=4"
                  BrowseName="0:DefaultBinary">
        <DisplayName>DefaultBinary</DisplayName>
        <Description>DefaultBinary</Description>
        <References>
            <Reference ReferenceType="HasEncoding"
                       IsForward="false">ns=1;i=3</Reference>
        </References>
    </UAObjectType>

rempAut avatar Feb 16 '24 09:02 rempAut