High level Functions and Node Class¶
High level node object, to access node attribute and browse address space
-
class
opcua.common.node.
Node
(server, nodeid)[source]¶ High level node object, to access node attribute, browse and populate address space. Node objects are usefull as-is but they do not expose the entire OPC-UA protocol. Feel free to look at the code of this class and call directly UA services methods to optimize your code
-
get_browse_name
()[source]¶ Get browse name of a node. A browse name is a QualifiedName object composed of a string(name) and a namespace index.
-
get_data_type_as_variant_type
()[source]¶ get data type of node as VariantType This only works if node is a variable, otherwise type may not be convertible to VariantType
-
get_access_level
()[source]¶ Get the access level attribute of the node as a set of AccessLevel enum values.
-
get_user_access_level
()[source]¶ Get the user access level attribute of the node as a set of AccessLevel enum values.
-
get_event_notifier
()[source]¶ Get the event notifier attribute of the node as a set of EventNotifier enum values.
-
set_event_notifier
(values)[source]¶ Set the event notifier attribute.
Parameters: values – an iterable of EventNotifier enum values.
-
get_value
()[source]¶ Get value of a node as a python type. Only variables ( and properties) have values. An exception will be generated for other node types. WARNING: on server side, this function returns a ref to object in ua database. Do not modify it if it is a mutable object unless you know what you are doing
-
get_data_value
()[source]¶ Get value of a node as a DataValue object. Only variables (and properties) have values. An exception will be generated for other node types. DataValue contain a variable value as a variant as well as server and source timestamps
-
set_array_dimensions
(value)[source]¶ Set attribute ArrayDimensions of node make sure it has the correct data type
-
set_value
(value, varianttype=None)[source]¶ 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, varianttype is then ignored * a ua.DataValue, you then have full control over data send to server WARNING: On server side, ref to object is directly saved in our UA db, if this is a mutable object and you modfy it afterward, then the object in db will be modified without any data change event generated
-
set_data_value
(value, varianttype=None)¶ 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, varianttype is then ignored * a ua.DataValue, you then have full control over data send to server WARNING: On server side, ref to object is directly saved in our UA db, if this is a mutable object and you modfy it afterward, then the object in db will be modified without any data change event generated
-
set_writable
(writable=True)[source]¶ Set node as writable by clients. A node is always writable on server side.
-
set_read_only
()[source]¶ Set a node as read-only for clients. A node is always writable on server side.
-
set_attribute
(attributeid, datavalue)[source]¶ Set an attribute of a node attributeid is a member of ua.AttributeIds datavalue is a ua.DataValue object
-
get_attribute
(attr)[source]¶ Read one attribute of a node result code from server is checked and an exception is raised in case of error
-
get_children
(refs=33, nodeclassmask=<NodeClass.Unspecified: 0>)[source]¶ Get all children of a node. By default hierarchical references and all node classes are returned. Other reference types may be given: References = 31 NonHierarchicalReferences = 32 HierarchicalReferences = 33 HasChild = 34 Organizes = 35 HasEventSource = 36 HasModellingRule = 37 HasEncoding = 38 HasDescription = 39 HasTypeDefinition = 40 GeneratesEvent = 41 Aggregates = 44 HasSubtype = 45 HasProperty = 46 HasComponent = 47 HasNotifier = 48 HasOrderedComponent = 49
-
get_properties
()[source]¶ return properties of node. properties are child nodes with a reference of type HasProperty and a NodeClass of Variable
-
get_variables
()[source]¶ return variables of node. properties are child nodes with a reference of type HasComponent and a NodeClass of Variable
-
get_methods
()[source]¶ return methods of node. properties are child nodes with a reference of type HasComponent and a NodeClass of Method
-
get_children_descriptions
(refs=33, nodeclassmask=<NodeClass.Unspecified: 0>, includesubtypes=True)[source]¶
-
get_references
(refs=31, direction=<BrowseDirection.Both: 2>, nodeclassmask=<NodeClass.Unspecified: 0>, includesubtypes=True)[source]¶ returns references of the node based on specific filter defined with:
refs = ObjectId of the Reference direction = Browse direction for references nodeclassmask = filter nodes based on specific class includesubtypes = If true subtypes of the reference (ref) are also included
-
get_referenced_nodes
(refs=31, direction=<BrowseDirection.Both: 2>, nodeclassmask=<NodeClass.Unspecified: 0>, includesubtypes=True)[source]¶ returns referenced nodes based on specific filter Paramters are the same as for get_references
-
get_path
(max_length=20, as_string=False)[source]¶ Attempt to find path of node from root node and return it as a list of Nodes. There might several possible paths to a node, this function will return one Some nodes may be missing references, so this method may return an empty list Since address space may have circular references, a max length is specified
-
get_parent
()[source]¶ returns parent of the node. A Node may have several parents, the first found is returned. This method uses reverse references, a node might be missing such a link, thus we will not find its parent.
-
get_child
(path)[source]¶ get a child specified by its path from this node. A path might be: * a string representing a qualified name. * a qualified name * a list of string * a list of qualified names
-
read_raw_history
(starttime=None, endtime=None, numvalues=0)[source]¶ Read raw history of a node result code from server is checked and an exception is raised in case of error If numvalues is > 0 and number of events in period is > numvalues then result will be truncated
-
history_read
(details)[source]¶ Read raw history of a node, low-level function result code from server is checked and an exception is raised in case of error
-
read_event_history
(starttime=None, endtime=None, numvalues=0, evtypes=2041)[source]¶ Read event history of a source node result code from server is checked and an exception is raised in case of error If numvalues is > 0 and number of events in period is > numvalues then result will be truncated
-
history_read_events
(details)[source]¶ Read event history of a node, low-level function result code from server is checked and an exception is raised in case of error
-
delete_reference
(target, reftype, forward=True, bidirectional=True)[source]¶ Delete given node’s references from address space
-
set_modelling_rule
(mandatory)[source]¶ Add a modelling rule reference to Node. When creating a new object type, its variable and child nodes will not be instanciated if they do not have modelling rule if mandatory is None, the modelling rule is removed
-
High level functions to create nodes
-
opcua.common.manage_nodes.
create_data_type
(parent, nodeid, bname, description=None)[source]¶ Create a new data type to be used in new variables, etc .. arguments are nodeid, browsename or namespace index, name
-
opcua.common.manage_nodes.
create_folder
(parent, nodeid, bname)[source]¶ create a child node folder arguments are nodeid, browsename or namespace index, name
-
opcua.common.manage_nodes.
create_method
(parent, *args)[source]¶ create a child method object This is only possible on server side!! args are nodeid, browsename, method_to_be_called, [input argument types], [output argument types] or idx, name, method_to_be_called, [input argument types], [output argument types] if argument types is specified, child nodes advertising what arguments the method uses and returns will be created a callback is a method accepting the nodeid of the parent as first argument and variants after. returns a list of variants
-
opcua.common.manage_nodes.
create_object
(parent, nodeid, bname, objecttype=None)[source]¶ create a child node object arguments are nodeid, browsename, [objecttype] or namespace index, name, [objecttype] if objectype is given (a NodeId) then the type node is instantiated inclusive its child nodes
-
opcua.common.manage_nodes.
create_object_type
(parent, nodeid, bname)[source]¶ Create a new object type to be instanciated in address space. arguments are nodeid, browsename or namespace index, name
-
opcua.common.manage_nodes.
create_property
(parent, nodeid, bname, val, varianttype=None, datatype=None)[source]¶ create a child node property args are nodeid, browsename, value, [variant type] or idx, name, value, [variant type]
-
opcua.common.manage_nodes.
create_reference_type
(parent, nodeid, bname, symmetric=True, inversename=None)[source]¶ Create a new reference type args are nodeid and browsename or idx and name
-
opcua.common.manage_nodes.
create_variable
(parent, nodeid, bname, val, varianttype=None, datatype=None)[source]¶ create a child node variable args are nodeid, browsename, value, [variant type], [data type] or idx, name, value, [variant type], [data type]
-
opcua.common.manage_nodes.
create_variable_type
(parent, nodeid, bname, datatype)[source]¶ Create a new variable type args are nodeid, browsename and datatype or idx, name and data type
-
opcua.common.manage_nodes.
delete_nodes
(server, nodes, recursive=False, delete_target_references=True)[source]¶ Delete specified nodes. Optionally delete recursively all nodes with a downward hierachic references to the node return the list of deleted node and the result
High level method related functions
-
opcua.common.methods.
call_method
(parent, methodid, *args)[source]¶ Call an OPC-UA method. methodid is browse name of child method or the nodeid of method as a NodeId object arguments are variants or python object convertible to variants. which may be of different types returns a list of values or a single value depending on the output of the method
-
opcua.common.methods.
call_method_full
(parent, methodid, *args)[source]¶ Call an OPC-UA method. methodid is browse name of child method or the nodeid of method as a NodeId object arguments are variants or python object convertible to variants. which may be of different types returns a CallMethodResult object with converted OutputArguments