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)
| 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 |