WindowsWeenie
WindowsWeenie

Reputation: 369

OPC UA asyncua python: new file directory created but it lacks the CreateFile method among its children

My problem appears to be very similar to this unanswered question: OPC UA asyncua python: new folder created but server never returns the methods but I have tried something slightly different. I initially tried to create a folder by calling the existing create_folder method, but that folder just appeared to be one I could place other nodes (or folders) inside rather than actual files, and I was trying to add support for transferring a file to the OPC-UA server. Instead the type that seemed to fit what I wanted was FileDirectory, which I could see in standard_address_space_services should have CreateFile as a child (precisely what is searched for in the create_file method of UaDirectory). To that end I created this method, largely copied from the create_folder method:

    async def add_directory(self, nodeid, bname):
        # This section was mostly copied from manage_nodes.create_folder
        nodeid, qname = _parse_nodeid_qname(nodeid, bname)
        parent = self.server.nodes.objects
        directory_node = make_node(
            self.server,
            await _create_object(parent.server, parent.nodeid,
                                 nodeid, qname, ua.ObjectIds.FileDirectoryType)
        )
        # This was mostly copied from standard_address_space_services
        # It doesn't currently work because self.server doesn't have an add_nodes method
        # standard_address_space_services.create_standard_address_space_Services gets called
        # when the internal server is initialized
        # But this doesn't result in any instance of the FileDirectoryType I create
        # having CreateFile as a child node
        # CreateFile is created as a child of node id 13354, "<FileDirectoryName>"
        # Which in turn is a child of 13353, FileDirectoryType, which I use above
        # attrs = ua.MethodAttributes(
        #     DisplayName=LocalizedText("CreateFile"),
        # )
        # node = ua.AddNodesItem(
        #     BrowseName=QualifiedName("CreateFile", 0),
        #     NodeClass_=NodeClass.Method,
        #     ParentNodeId=NumericNodeId(directory_node.nodeid.Identifier, 0),
        #     ReferenceTypeId=NumericNodeId(47, 0),
        #     NodeAttributes=attrs,
        # )
        # self.server.add_nodes([node])
        return directory_node

Unfortunately, as indicated by those comments, merely creating an object with the FileDirectory type doesn't give it the methods specified in the standard services and hence it will still fail if I call create_file on it. The FileDirectory type must have been added for a reason, but I can't see how to create a working instance of one. These are the lines I use attempting to create a file with a node created by the method above:

ua_directory = UaDirectory(transfer_folder_node)
transfer_file = await ua_directory.create_file("test_file.txt", True)

Upvotes: 1

Views: 283

Answers (0)

Related Questions