@@ 106-126 (lines=21) @@ | ||
103 | ) |
|
104 | ||
105 | ||
106 | async def create_variable(parent, nodeid, bname, val, varianttype=None, datatype=None): |
|
107 | """ |
|
108 | create a child node variable |
|
109 | args are nodeid, browsename, value, [variant type], [data type] |
|
110 | or idx, name, value, [variant type], [data type] |
|
111 | """ |
|
112 | try: |
|
113 | _check_browsename_exist(parent, bname) |
|
114 | except ua.uaerrors.BadBrowseNameDuplicated as bnameerr: |
|
115 | _logger.error(bnameerr) |
|
116 | return |
|
117 | nodeid, qname = _parse_nodeid_qname(nodeid, bname) |
|
118 | var = ua.Variant(val, varianttype) |
|
119 | if datatype and isinstance(datatype, int): |
|
120 | datatype = ua.NodeId(datatype, 0) |
|
121 | if datatype and not isinstance(datatype, ua.NodeId): |
|
122 | raise RuntimeError("datatype argument must be a nodeid or an int refering to a nodeid") |
|
123 | ||
124 | return make_node( |
|
125 | parent.server, |
|
126 | await _create_variable(parent.server, parent.nodeid, nodeid, qname, var, datatype=datatype, isproperty=False) |
|
127 | ) |
|
128 | ||
129 | ||
@@ 130-149 (lines=20) @@ | ||
127 | ) |
|
128 | ||
129 | ||
130 | async def create_variable_type(parent, nodeid, bname, datatype): |
|
131 | """ |
|
132 | Create a new variable type |
|
133 | args are nodeid, browsename and datatype |
|
134 | or idx, name and data type |
|
135 | """ |
|
136 | try: |
|
137 | _check_browsename_exist(parent, bname) |
|
138 | except ua.uaerrors.BadBrowseNameDuplicated as bnameerr: |
|
139 | _logger.error(bnameerr) |
|
140 | return |
|
141 | nodeid, qname = _parse_nodeid_qname(nodeid, bname) |
|
142 | if datatype and isinstance(datatype, int): |
|
143 | datatype = ua.NodeId(datatype, 0) |
|
144 | if datatype and not isinstance(datatype, ua.NodeId): |
|
145 | raise RuntimeError( |
|
146 | f"Data type argument must be a nodeid or an int refering to a nodeid, received: {datatype}") |
|
147 | return make_node( |
|
148 | parent.server, |
|
149 | await _create_variable_type(parent.server, parent.nodeid, nodeid, qname, datatype) |
|
150 | ) |
|
151 | ||
152 | ||
@@ 83-102 (lines=20) @@ | ||
80 | ) |
|
81 | ||
82 | ||
83 | async def create_property(parent, nodeid, bname, val, varianttype=None, datatype=None): |
|
84 | """ |
|
85 | create a child node property |
|
86 | args are nodeid, browsename, value, [variant type] |
|
87 | or idx, name, value, [variant type] |
|
88 | """ |
|
89 | try: |
|
90 | _check_browsename_exist(parent, bname) |
|
91 | except ua.uaerrors.BadBrowseNameDuplicated as bnameerr: |
|
92 | _logger.error(bnameerr) |
|
93 | return |
|
94 | nodeid, qname = _parse_nodeid_qname(nodeid, bname) |
|
95 | var = ua.Variant(val, varianttype) |
|
96 | if datatype and isinstance(datatype, int): |
|
97 | datatype = ua.NodeId(datatype, 0) |
|
98 | if datatype and not isinstance(datatype, ua.NodeId): |
|
99 | raise RuntimeError("datatype argument must be a nodeid or an int refering to a nodeid") |
|
100 | return make_node( |
|
101 | parent.server, |
|
102 | await _create_variable(parent.server, parent.nodeid, nodeid, qname, var, datatype=datatype, isproperty=True) |
|
103 | ) |
|
104 | ||
105 |