opcua-snapshot 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Loader.js +7 -4
- package/package.json +5 -2
- package/opcua.json +0 -579216
- package/test.js +0 -103
package/test.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
const fs = require ('node:fs')
|
|
2
|
-
const {
|
|
3
|
-
OPCUAClient,
|
|
4
|
-
OPCUAServer,
|
|
5
|
-
} = require ('node-opcua')
|
|
6
|
-
const {
|
|
7
|
-
Dumper,
|
|
8
|
-
Loader
|
|
9
|
-
} = require ('.')
|
|
10
|
-
|
|
11
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
12
|
-
|
|
13
|
-
async function main () {
|
|
14
|
-
|
|
15
|
-
// await dump (
|
|
16
|
-
// 'opcua.json'
|
|
17
|
-
// , 'opc.tcp://localhost:4840/'
|
|
18
|
-
// , {ns: 0, id: 'i=84'}
|
|
19
|
-
// )
|
|
20
|
-
|
|
21
|
-
await run (
|
|
22
|
-
'opcua.json'
|
|
23
|
-
, 4841
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
29
|
-
|
|
30
|
-
async function dump (filePath, endpointUrl, rootNode) {
|
|
31
|
-
|
|
32
|
-
const client = OPCUAClient.create ({endpointMustExist: false})
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
|
|
36
|
-
await client.connect (endpointUrl)
|
|
37
|
-
|
|
38
|
-
const session = await client.createSession ()
|
|
39
|
-
|
|
40
|
-
const dumper = new Dumper (session)
|
|
41
|
-
|
|
42
|
-
// dumper.on ('start', _ => console.log (_))
|
|
43
|
-
// dumper.on ('warning', _ => console.log (_))
|
|
44
|
-
// dumper.on ('finish', _ => console.log ('finish'))
|
|
45
|
-
|
|
46
|
-
const snapshot = await dumper.dump (rootNode)
|
|
47
|
-
|
|
48
|
-
fs.writeFileSync (filePath, JSON.stringify (snapshot, null, 2))
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
|
|
53
|
-
await client.disconnect ()
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
60
|
-
|
|
61
|
-
async function run (fn, port) {
|
|
62
|
-
|
|
63
|
-
const server = new OPCUAServer ({endpoints: [{port}]})
|
|
64
|
-
|
|
65
|
-
await server.initialize ()
|
|
66
|
-
|
|
67
|
-
const loader = new Loader (server)
|
|
68
|
-
|
|
69
|
-
{
|
|
70
|
-
|
|
71
|
-
const MS_IN_DAY = 1000 * 60 * 60 * 24, values = [0.0], dates = [(new Date (new Date ().toJSON ().substring (0, 10) + 'T00:00:00')).getTime ()]
|
|
72
|
-
|
|
73
|
-
for (let i = 0; i < 10; i ++) {
|
|
74
|
-
|
|
75
|
-
values.push (values [i] + Math.random ())
|
|
76
|
-
|
|
77
|
-
dates.unshift (dates [0] - MS_IN_DAY)
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
loader.on ('var', varNode => {
|
|
82
|
-
|
|
83
|
-
if (!varNode.historizing) return
|
|
84
|
-
|
|
85
|
-
varNode.accessLevel = 4
|
|
86
|
-
|
|
87
|
-
loader.setValues (varNode, values, dates)
|
|
88
|
-
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
loader.load (JSON.parse (fs.readFileSync (fn)))
|
|
94
|
-
|
|
95
|
-
await server.start ()
|
|
96
|
-
|
|
97
|
-
loader.setValue ('ns=2;s=GIUSController.ActiveChannel', 'TELEPATHY')
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
102
|
-
|
|
103
|
-
main ().then (_ => _, _ => console.log (_))
|