opcua.common package¶
Submodules¶
opcua.common.event module¶
opcua.common.instanciate module¶
opcua.common.manage_nodes module¶
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.methods module¶
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
opcua.common.node module¶
High level node object, to access node attribute and browse address space
-
class
opcua.common.node.
Node
(server, nodeid)[source]¶ Bases:
object
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
-
delete_reference
(target, reftype, forward=True, bidirectional=True)[source]¶ Delete given node’s references from address space
-
get_access_level
()[source]¶ Get the access level attribute of the node as a set of AccessLevel enum values.
-
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_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_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
-
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_children_descriptions
(refs=33, nodeclassmask=<NodeClass.Unspecified: 0>, includesubtypes=True)[source]¶
-
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_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
-
get_event_notifier
()[source]¶ Get the event notifier attribute of the node as a set of EventNotifier enum values.
-
get_methods
()[source]¶ return methods of node. properties are child nodes with a reference of type HasComponent and a NodeClass of Method
-
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_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_properties
()[source]¶ return properties of node. properties are child nodes with a reference of type HasProperty and a NodeClass of Variable
-
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_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_user_access_level
()[source]¶ Get the user access level attribute of the node as a set of AccessLevel 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_variables
()[source]¶ return variables of node. properties are child nodes with a reference of type HasComponent and a NodeClass of Variable
-
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
-
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
-
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
-
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
-
register
()[source]¶ Register node for faster read and write access (if supported by server) Rmw: This call modifies the nodeid of the node, the original nodeid is available as node.basenodeid
-
set_array_dimensions
(value)[source]¶ Set attribute ArrayDimensions of node make sure it has the correct data type
-
set_attribute
(attributeid, datavalue)[source]¶ Set an attribute of a node attributeid is a member of ua.AttributeIds datavalue is a ua.DataValue object
-
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_event_notifier
(values)[source]¶ Set the event notifier attribute.
Parameters: values – an iterable of EventNotifier enum values.
-
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
-
set_read_only
()[source]¶ Set a node as read-only for clients. A node is always writable on server side.
-
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
-
opcua.common.subscription module¶
high level interface to subscriptions
-
class
opcua.common.subscription.
DataChangeNotif
(subscription_data, monitored_item)[source]¶ Bases:
object
To be send to clients for every datachange notification from server
-
class
opcua.common.subscription.
SubHandler
[source]¶ Bases:
object
Subscription Handler. To receive events from server for a subscription This class is just a sample class. Whatever class having these methods can be used
-
class
opcua.common.subscription.
Subscription
(server, params, handler)[source]¶ Bases:
object
Subscription object returned by Server or Client objects. The object represent a subscription to an opc-ua server. This is a high level class, especially subscribe_data_change and subscribe_events methods. If more control is necessary look at code and/or use create_monitored_items method.
-
create_monitored_items
(monitored_items)[source]¶ low level method to have full control over subscription parameters Client handle must be unique since it will be used as key for internal registration of data
-
deadband_monitor
(var, deadband_val, deadbandtype=1, queuesize=0, attr=<AttributeIds.Value: 13>)[source]¶ Method to create a subscription with a Deadband Value. Default deadband value type is absolute. Return a handle which can be used to unsubscribe :param var: Variable to which you want to subscribe :param deadband_val: Absolute float value :param deadbandtype: Default value is 1 (absolute), change to 2 for percentage deadband :param queuesize: Wanted queue size, default is 1
-
delete
()[source]¶ Delete subscription on server. This is automatically done by Client and Server classes on exit
-
modify_monitored_item
(handle, new_samp_time, new_queuesize=0, mod_filter_val=-1)[source]¶ Modify a monitored item. :param handle: Handle returned when originally subscribing :param new_samp_time: New wanted sample time :param new_queuesize: New wanted queuesize, default is 0 :param mod_filter_val: New deadband filter value :return: Return a Modify Monitored Item Result
-
reconciliate
(monitored_items)[source]¶ Reconciliate client monitored_items with its server counterpart. :param monitored_items_srv: monitored items handles from server :return: Number of mi added and deleted to the client subscription
-
subscribe_data_change
(nodes, attr=<AttributeIds.Value: 13>, queuesize=0)[source]¶ Subscribe for data change events for a node or list of nodes. default attribute is Value. Return a handle which can be used to unsubscribe If more control is necessary use create_monitored_items method
-
subscribe_events
(sourcenode=2253, evtypes=2041, evfilter=None, queuesize=0)[source]¶ Subscribe to events from a node. Default node is Server node. In most servers the server node is the only one you can subscribe to. if evtypes is not provided, evtype defaults to BaseEventType if evtypes is a list or tuple of custom event types, the events will be filtered to the supplied types Return a handle which can be used to unsubscribe
-
opcua.common.uaerrors module¶
opcua.common.utils module¶
Helper function and classes that do not rely on opcua library. Helper function and classes depending on ua object are in ua_utils.py
-
class
opcua.common.utils.
Buffer
(data, start_pos=0, size=-1)[source]¶ Bases:
object
alternative to io.BytesIO making debug easier and added a few conveniance methods
-
class
opcua.common.utils.
SocketWrapper
(sock)[source]¶ Bases:
object
wrapper to make it possible to have same api for normal sockets, socket from asyncio, StringIO, etc….
-
class
opcua.common.utils.
ThreadLoop
[source]¶ Bases:
threading.Thread
run an asyncio loop in a thread
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
opcua.common.xmlimporter module¶
add nodes defined in XML to address space format is the one from opc-ua specification
opcua.common.xmlparser module¶
parse xml file from opcua-spec