@jsh/opcua

Since v8.0.52

Client

The OPCUA client.

Usage example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
opcua = require("@jsh/opcua");
nodes = [
    "ns=1;s=NoPermVariable",
    "ns=1;s=ReadWriteVariable",
    "ns=1;s=ReadOnlyVariable",
    "ns=1;s=NoAccessVariable",
];

try {
    client = new opcua.Client({ endpoint: "opc.tcp://localhost:4840" });
    vs = client.read({
        nodes: nodes,
        timestampsToReturn: opcua.TimestampsToReturn.Both
    });
    vs.forEach((v, idx) => {
        console.log(nodes[idx], v.status, v.statusCode, v.value, v.type);
    })
} catch (e) {
    console.log("Error:", e.message);
} finally {
    if (client !== undefined) client.close();
}
Creation
ConstructorDescription
new Client(options)Instantiates a opcua client object with an options
Options
OptionTypeDefaultDescription
endpointString""server address
readRetryIntervalNumber100read retry interval in ms.
messageSecurityModeMessageSecurityMode

close()

Disconnect.

Syntax
close()
Parameters

None.

Return value

None.

read()

Syntax
read(read_request)
Parameters

read_request Object ReadRequest

Return value

Object[] Array of ReadResult

vs = client.read({
    nodes: [ "ns=1;s=ro_bool", "ns=1;s=rw_int32"],
    timestampsToReturn:ua.TimestampsToReturn.Both
});
vs.forEach((v, idx) => {
    console.log(nodes[idx], v.status, v.statusCode, v.value, v.type);
})

write()

Syntax
write(...write_request)
Parameters

write_request Object Variable length of WriteRequest

Return value

Object WriteResult

rsp = client.write(
    {node: "ns=1;s=rw_bool", value: false},
    {node: "ns=1;s=rw_int32", value: 1234}
)
console.log("results:", rsp.results);

ReadRequest

OptionTypeDefaultDescription
nodesString[]array of node IDs
maxAgeNumber100read retry interval in ms.
timestampsToReturnTimestampToReturn

ReadResult

Properties
PropertyTypeDescription
statusNumber
statusTextString
statusCodeString
valueany
sourceTimestampNumberUnix epoch (milliseconds)
sourceTimestampNumberUnix epoch (milliseconds)

WriteRequest

Properties
PropertyTypeDescription
nodeStringnode ID
valueanyvalue to write

WriteResult

Properties
PropertyTypeDescription
resultsNumber[]array of status codes
timestampNumberUnix epoch (milliseconds)
stringTablesString[]array of strings

MessageSecurityMode

  • MessageSecurityMode.None
  • MessageSecurityMode.Sign
  • MessageSecurityMode.SignAndEncrypt

TimestampToReturn

  • TimestampToReturn.Source
  • TimestampToReturn.Server
  • TimestampToReturn.Both
  • TimestampToReturn.Neither
Last updated on