Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support nested structures. #1703

Closed
wants to merge 1 commit into from

Conversation

Scheibengraber
Copy link

@Scheibengraber Scheibengraber commented Aug 30, 2024

For nested structures the function make_structure_code in asyncua.common.structures104.py raised a RuntimeError exception.
I now added for structure fields, which are structures again a further elif branch, which checks if the datatype is different and if it is a StrucutreField and then I assign the type uaprotocol_auto.StructureField.

My first tests with nested structures look quite good:

class ReadOnly:

    '''
    ReadOnly structure autogenerated from StructureDefinition object
    '''

    data_type = ua.NodeId.from_string('''ns=4;i=3007''')

    Header: ua.uaprotocol_auto.StructureField = field(default_factory=ua.uaprotocol_auto.StructureField)
    Return_data: ua.Return_data = field(default_factory=ua.Return_data)

And also structure with base types looks good:

@dataclass
class ReadWrite:

    '''
    ReadWrite structure autogenerated from StructureDefinition object
    '''

    data_type = ua.NodeId.from_string('''ns=4;i=3008''')

    KeepAlive: ua.Boolean = True
    Res_Bit1: ua.Boolean = True
    Res_Bit2: ua.Boolean = True
    Res_Bit3: ua.Boolean = True
    Res_Bit4: ua.Boolean = True
    Res_Bit5: ua.Boolean = True
    Res_Bit6: ua.Boolean = True
    Res_Bit7: ua.Boolean = True

If the pull request gets accepted I will remove the print statement before we/you merge it into master.

@Scheibengraber
Copy link
Author

Scheibengraber commented Aug 30, 2024

Can you support me why one pytest in Python package / build (pypy-3.10) has failed? It should have nothing to do with my changes.

@Scheibengraber
Copy link
Author

Scheibengraber commented Aug 30, 2024

Pull request can be abandoned. We used in the PLC the custom structure name Header, which is already defined. This is why the custom structure data type definition wasn't loaded, because it already exists and I had overwrite_existing=False in load_data_type_definitions`.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant