/
server_with_da_variables.js
44 lines (29 loc) · 1.16 KB
/
server_with_da_variables.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* global console, require */
var opcua = require("node-opcua");
const server = new opcua.OPCUAServer({
port: 4334 // the port of the listening socket of the server
});
function post_initialize() {
const addressSpace = server.engine.addressSpace;
const namespace = addressSpace.getOwnNamespace();
const myDevice = namespace.addObject({
organizedBy: addressSpace.rootFolder.objects,
browseName: "MyDevice"
});
const fakeValue = 1;
const analogItem = namespace.addAnalogDataItem({
componentOf: myDevice,
browseName: "TemperatureSensor",
definition: "(tempA -25) + tempB",
valuePrecision: 0.5,
engineeringUnitsRange: { low: 100 , high: 200},
instrumentRange: { low: -100 , high: +200},
engineeringUnits: opcua.standardUnits.degree_celsius,
dataType: "Double",
value: { get: function(){return new opcua.Variant({dataType: opcua.DataType.Double , value: fakeValue}); } }
});
}
server.initialize(post_initialize);
server.start(function() {
console.log("Server is now listening ... ( press CTRL+C to stop)");
});