MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / set_value

Method set_value

opcua/common/node.py:195–217  ·  view source on GitHub ↗

Set value of a node. Only variables(properties) have values. An exception will be generated for other node types. value argument is either: * a python built-in type, converted to opc-ua optionnaly using the variantype argument. * a ua.Variant, variant

(self, value, varianttype=None)

Source from the content-addressed store, hash-verified

193 return res.Value.Value
194
195 def set_value(self, value, varianttype=None):
196 """
197 Set value of a node. Only variables(properties) have values.
198 An exception will be generated for other node types.
199 value argument is either:
200 * a python built-in type, converted to opc-ua
201 optionnaly using the variantype argument.
202 * a ua.Variant, varianttype is then ignored
203 * a ua.DataValue, you then have full control over data send to server
204 WARNING: On server side, ref to object is directly saved in our UA db, if this is a mutable object
205 and you modfy it afterward, then the object in db will be modified without any
206 data change event generated
207 """
208 datavalue = None
209 if isinstance(value, ua.DataValue):
210 datavalue = value
211 elif isinstance(value, ua.Variant):
212 datavalue = ua.DataValue(value)
213 datavalue.SourceTimestamp = datetime.utcnow()
214 else:
215 datavalue = ua.DataValue(ua.Variant(value, varianttype))
216 datavalue.SourceTimestamp = datetime.utcnow()
217 self.set_attribute(ua.AttributeIds.Value, datavalue)
218
219 set_data_value = set_value
220

Callers 15

setup_nodesMethod · 0.95
startMethod · 0.95
uaserverFunction · 0.80
register_namespaceMethod · 0.80
_set_current_timeMethod · 0.80
__init__Method · 0.80
set_application_uriMethod · 0.80
set_build_infoMethod · 0.80
register_namespaceMethod · 0.80
set_dict_byte_stringMethod · 0.80
test_functional_basicMethod · 0.80

Calls 1

set_attributeMethod · 0.95