1
|
|
|
|
2
|
1 |
|
import os.path |
3
|
|
|
|
4
|
1 |
|
import opcua |
5
|
1 |
|
from opcua.server.users import User |
6
|
1 |
|
from opcua import ua |
7
|
|
|
|
8
|
1 |
|
from opcua.server.standard_address_space.standard_address_space_part3 import create_standard_address_space_Part3 |
9
|
1 |
|
from opcua.server.standard_address_space.standard_address_space_part4 import create_standard_address_space_Part4 |
10
|
1 |
|
from opcua.server.standard_address_space.standard_address_space_part5 import create_standard_address_space_Part5 |
11
|
1 |
|
from opcua.server.standard_address_space.standard_address_space_part8 import create_standard_address_space_Part8 |
12
|
1 |
|
from opcua.server.standard_address_space.standard_address_space_part9 import create_standard_address_space_Part9 |
13
|
1 |
|
from opcua.server.standard_address_space.standard_address_space_part10 import create_standard_address_space_Part10 |
14
|
1 |
|
from opcua.server.standard_address_space.standard_address_space_part11 import create_standard_address_space_Part11 |
15
|
1 |
|
from opcua.server.standard_address_space.standard_address_space_part13 import create_standard_address_space_Part13 |
16
|
|
|
|
17
|
1 |
|
class PostponeReferences(object): |
18
|
1 |
|
def __init__(self, server): |
19
|
1 |
|
self.server = server |
20
|
1 |
|
self.postponed = {} |
21
|
|
|
|
22
|
1 |
|
def add_nodes(self, addnodeitems): |
23
|
1 |
|
results = self.server.add_nodes(addnodeitems) |
24
|
1 |
|
for i,r in zip(addnodeitems, results): |
25
|
1 |
|
if r.StatusCode.is_good(): |
26
|
1 |
|
self.add_references(self.postponed.pop(i.RequestedNewNodeId, [])) |
27
|
1 |
|
return results |
28
|
|
|
|
29
|
1 |
|
def add_references(self, refs): |
30
|
1 |
|
results = [] |
31
|
1 |
|
for ref in refs: |
32
|
1 |
|
if ref.TargetNodeId in self.server._aspace: |
33
|
1 |
|
results.append(self.server._add_reference(ref, User.Admin)) |
34
|
|
|
else: |
35
|
1 |
|
if ref.TargetNodeId in self.postponed: |
36
|
1 |
|
self.postponed[ref.TargetNodeId].append(ref) |
37
|
|
|
else: |
38
|
1 |
|
self.postponed[ref.TargetNodeId] = [ref] |
39
|
1 |
|
results.append(ua.StatusCode()) |
40
|
1 |
|
return results |
41
|
1 |
|
def __enter__(self): |
42
|
1 |
|
return self |
43
|
1 |
|
def __exit__(self, exc_type, exc_val, exc_tb): |
44
|
1 |
|
if exc_type is None and exc_val is None: |
45
|
1 |
|
for refs in self.postponed.values(): |
46
|
|
|
self.server.add_references(refs) |
47
|
|
|
|
48
|
1 |
|
def fill_address_space(nodeservice): |
49
|
1 |
|
with PostponeReferences(nodeservice) as server: |
50
|
1 |
|
create_standard_address_space_Part3(server) |
51
|
1 |
|
create_standard_address_space_Part4(server) |
52
|
1 |
|
create_standard_address_space_Part5(server) |
53
|
1 |
|
create_standard_address_space_Part8(server) |
54
|
1 |
|
create_standard_address_space_Part9(server) |
55
|
1 |
|
create_standard_address_space_Part10(server) |
56
|
1 |
|
create_standard_address_space_Part11(server) |
57
|
|
|
create_standard_address_space_Part13(server) |
58
|
|
|
|