コード例 #1
0
    def mutate(
        self, info, server, name, node_id, parent_id,
        value=None, writable=True
    ):

        server = getServer(server)
        result = server.add_node(name, node_id, parent_id, value, writable)

        if result.get("value") is not None:
            variable = OPCUAVariable(
                value=result.get("value"),
                data_type=result.get("dataType"),
                source_timestamp=result.get("sourceTimestamp"),
                status_code=result.get("statusCode"),
            )
        else:
            variable = None

        return AddNode(
            name=result["name"],
            node_id=result["nodeId"],
            variable=variable,
            server=server.name,
            writable=writable,
            ok=True
        )
コード例 #2
0
 def set_node(self):
     if self.node is None:
         if self.server_object is None:
             self.server_object = getServer(self.server)
         self.node = self.server_object.get_node(self.node_id)
         self.node_key = self.server + "/" + self.node_id
     return
コード例 #3
0
    async def mutate(self, info, server, node_id, value, dataType=None):

        server = getServer(server)
        ok, writeTime = await server.set_node_attribute(
            node_id, "Value", value, dataType
        )
        return SetNodeValue(ok=ok, writeTime=writeTime)
コード例 #4
0
    def mutate(self, info, name, endPointAddress):

        ok = False
        try:
            servers = getServer(name)
            raise GraphQLError("Server with that name is already configured")
        except ValueError:
            pass

        with open(
            os.path.join(os.getcwd(), "servers.json"),
            "r+"
        ) as serversFile:
            servers = json.load(serversFile)
            servers["servers"].append({
                "name": name,
                "endPointAddress": endPointAddress
            })
            serversFile.seek(0)
            json.dump(servers, serversFile, indent=4)
            serversFile.truncate()
            ok = True

        setupServers()
        return AddServer(ok=ok)
コード例 #5
0
    def mutate(self, info, name):

        ok = False
        server = getServer(name)
        try:
            server.sub.delete()
        except Exception as e:
            print(type(e).__name__)
            print(str(e))
            pass
        server.sub = None
        server.subscriptions.clear()
        ok = True

        return ClearServerSubscriptions(ok=ok)
コード例 #6
0
    async def batch_load_fn(self, attributeKeys):
        """
        Iterates through the attributeKeys and retrieves data
        from OPC UA servers based on the attributeKey values.

        Arguments
        attributeKeys:  List of strings with required infromation
                        to retrieve the attributes from OPC UA servers.
        Template:       "Server/NodeId/Attribute"
        Example:        "TestServer/ns=2;i=2/Value"

        Results
        sortedResults:  List of values returned by the OPC UA server
                        for each attribute. Also includes OPC UA read
                        time with each attribute.
                        In same order as attributeKeys.
        Example:        [<opcua_object>, readTime]
        """

        servers = defaultdict(list)
        i = 0
        for attribute in attributeKeys:
            info = attribute.split("/")
            servers[info[0]].append([i, info[1], info[2]])
            i += 1

        sortedResults = [None] * len(attributeKeys)
        for serverName, attributes in servers.items():
            params = ua.ReadParameters()
            server = getServer(serverName)
            for info in attributes:
                rv = ua.ReadValueId()
                if info[1] == "":
                    rv.NodeId = ua.NodeId.from_string(server.rootNodeId)
                else:
                    rv.NodeId = ua.NodeId.from_string(info[1])
                rv.AttributeId = ua.AttributeIds[info[2]]
                params.NodesToRead.append(rv)

            results, readTime = await server.read(params)

            i = 0
            for info in attributes:
                sortedResults[info[0]] = [results[i], readTime]
                i += 1

        return sortedResults
コード例 #7
0
    def mutate(self, info, name):

        ok = False
        server = getServer(name)
        with open(
            os.path.join(os.getcwd(), "servers.json"),
            "r+"
        ) as serversFile:
            servers = json.load(serversFile)
            i = 0
            for server in servers["servers"]:
                if server["name"] == name:
                    del servers["servers"][i]
                    ok = True
                    break
                i += 1
            serversFile.seek(0)
            json.dump(servers, serversFile, indent=4)
            serversFile.truncate()

        setupServers()
        return AddServer(ok=ok)
コード例 #8
0
 def resolve_node(self, info, server, node_id):
     """
     Get specified attributes of an OPC UA node.
     """
     server = getServer(server)
     return OPCUANode(server=server.name, node_id=node_id)
コード例 #9
0
 def resolve_subscriptions(self, info):
     server = getServer(self.name)
     return server.subscriptions.keys()
コード例 #10
0
    def mutate(self, info, server, node_id, description):

        server = getServer(server)
        ok = server.set_node_attribute(node_id, "Description", description)
        return SetNodeDescription(ok=ok)
コード例 #11
0
    def mutate(self, info, server, node_id, recursive=True):

        server = getServer(server)
        ok = server.delete_node(node_id, recursive)
        return DeleteNode(ok=ok)