我正在学习节点opc-ua并且已经遵循了GitHub页面中为sample_server.js和simple_client.js提供的示例.
在sample_server中,我在构造服务器的地址空间时添加一个变量,例如:
//this code is in the server
addressSpace.addVariable({
componentOf: device,
nodeId: "ns=1;s=variable_1",
browseName: "MyVariable1",
dataType: "Double",
value: {
get: function () {
return new opcua.Variant({ dataType: opcua.DataType.Double, value: variable1 });
}
}
});
Run Code Online (Sandbox Code Playgroud)
以下是整个服务器代码供参考:
var opcua = require("node-opcua");
var server = new opcua.OPCUAServer({
port: 4334, // the port of the listening socket of the server
resourcePath: "UA/MyLittleServer", // this path will be added to the endpoint resource name
buildInfo: {
productName: "MySampleServer1",
buildNumber: "7658",
buildDate: new Date(2014, 5, 2) …
Run Code Online (Sandbox Code Playgroud)