javaidentifieropc-uamilo

name=Bad_NodeIdUnknown, value=0x80340000, quality=bad (opc ua milo WriteExample about the NodeId)


I would like to have a test to write "1" into kepware(PLC) address through opc ua milo client. I get the client from GitHub , the URL is https://github.com/eclipse/milo . But I always got inaccurate information, like this:

[main] INFO o.e.m.examples.client.WriteExample - StatusCode{name=Bad_NodeIdUnknown, value=0x80340000, quality=bad}

Meanwhile, I can successfully read the data from kepware(PLC) .

My opc tagname is "AFSM010_WriteRFID" ,the channalname is "FE6" and the devicename is "AFSM" . So , what's the second parameter of NodeId ? ??

public class WriteExample implements ClientExample {

    public static void main(String[] args) throws Exception {
        WriteExample example = new WriteExample();

        new ClientExampleRunner(example).run();
    }

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
        // synchronous connect
        client.connect().get();

//        List<NodeId> nodeIds = ImmutableList.of(new NodeId(2, "HelloWorld/ScalarTypes/Int32"));
//        NodeId nodeId_Tag1 = new NodeId(3, "FE6.AFSM.AFSM010_WriteRFID");
        NodeId nodeId_Tag1 = new NodeId(3, "AFSM010_WriteRFID");
        List<NodeId> nodeIds = ImmutableList.of(nodeId_Tag1);

//        for (int i = 0; i < 10; i++) {
            Variant v = new Variant(5);

            // don't write status or timestamps
            DataValue dv = new DataValue(v, null, null);

            // write asynchronously....
            CompletableFuture<List<StatusCode>> f =
                client.writeValues(nodeIds, ImmutableList.of(dv));

            // ...but block for the results so we write in order
            List<StatusCode> statusCodes = f.get();
            StatusCode status = statusCodes.get(0);

            if (status.isGood()) {
                logger.info("Wrote '{}' to nodeId={}", v, nodeIds.get(0));
            }
        logger.info("this is the end : status " + status.toString());
//        }

        future.complete(client);
    }

}

Solution

  • I would suggest that you connect to Kepware with a client like UaExpert and browse the address space, find the Node(s) you're interested in, and take a look at how Kepware is formatting the NodeIds.

    Every server will have its own "rules" for how it makes NodeIds. You can't derive a NodeId from just knowing the "tag name" without know the rules for that server.

    It is expected that you discover Nodes and NodeIds either by browsing or by some out-of-band mechanism where you already know the format.