Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_custom_type(test, type, base_type, node_class=None):
base = opcua.Node(test.opc.iserver.isession, ua.NodeId(base_type))
test.assertTrue(type in base.get_children())
nodes = type.get_referenced_nodes(refs=ua.ObjectIds.HasSubtype, direction=ua.BrowseDirection.Inverse, includesubtypes=True)
test.assertEqual(base, nodes[0])
properties = type.get_properties()
if node_class:
test.assertEqual(node_class, type.get_node_class())
test.assertIsNot(properties, None)
test.assertEqual(len(properties), 2)
test.assertTrue(type.get_child("2:PropertyNum") in properties)
test.assertEqual(type.get_child("2:PropertyNum").get_data_value().Value.VariantType, ua.VariantType.Int32)
test.assertTrue(type.get_child("2:PropertyString") in properties)
test.assertEqual(type.get_child("2:PropertyString").get_data_value().Value.VariantType, ua.VariantType.String)
def check_custom_type(test, type, base_type):
base = opcua.Node(test.opc.iserver.isession, ua.NodeId(base_type))
test.assertTrue(type in base.get_children())
nodes = type.get_referenced_nodes(refs=ua.ObjectIds.HasSubtype, direction=ua.BrowseDirection.Inverse, includesubtypes=True)
test.assertEqual(base, nodes[0])
properties = type.get_properties()
test.assertIsNot(properties, None)
test.assertEqual(len(properties), 2)
test.assertTrue(type.get_child("2:PropertyNum") in properties)
test.assertEqual(type.get_child("2:PropertyNum").get_data_value().Value.VariantType, ua.VariantType.Int32)
test.assertTrue(type.get_child("2:PropertyString") in properties)
test.assertEqual(type.get_child("2:PropertyString").get_data_value().Value.VariantType, ua.VariantType.String)
def __init__(self, server):
self.root = Node(server, ObjectIds.RootFolder)
self.objects = Node(server, ObjectIds.ObjectsFolder)
self.server = Node(server, ObjectIds.Server)
self.types = Node(server, ObjectIds.TypesFolder)
self.base_object_type = Node(server, ObjectIds.BaseObjectType)
self.base_data_type = Node(server, ObjectIds.BaseDataType)
self.base_event_type = Node(server, ObjectIds.BaseEventType)
self.base_variable_type = Node(server, ObjectIds.BaseVariableType)
self.folder_type = Node(server, ObjectIds.FolderType)
self.enum_data_type = Node(server, ObjectIds.Enumeration)
self.types = Node(server, ObjectIds.TypesFolder)
self.data_types = Node(server, ObjectIds.DataTypesFolder)
self.event_types = Node(server, ObjectIds.EventTypesFolder)
self.reference_types = Node(server, ObjectIds.ReferenceTypesFolder)
self.variable_types = Node(server, ObjectIds.VariableTypesFolder)
self.object_types = Node(server, ObjectIds.ObjectTypesFolder)
self.namespace_array = Node(server, ObjectIds.Server_NamespaceArray)
self.opc_binary = Node(server, ObjectIds.OPCBinarySchema_TypeSystem)
def __init__(self, server):
self.root = Node(server, ObjectIds.RootFolder)
self.objects = Node(server, ObjectIds.ObjectsFolder)
self.server = Node(server, ObjectIds.Server)
self.types = Node(server, ObjectIds.TypesFolder)
self.base_object_type = Node(server, ObjectIds.BaseObjectType)
self.base_data_type = Node(server, ObjectIds.BaseDataType)
self.base_event_type = Node(server, ObjectIds.BaseEventType)
self.base_variable_type = Node(server, ObjectIds.BaseVariableType)
self.folder_type = Node(server, ObjectIds.FolderType)
self.enum_data_type = Node(server, ObjectIds.Enumeration)
self.types = Node(server, ObjectIds.TypesFolder)
self.data_types = Node(server, ObjectIds.DataTypesFolder)
self.event_types = Node(server, ObjectIds.EventTypesFolder)
self.reference_types = Node(server, ObjectIds.ReferenceTypesFolder)
self.variable_types = Node(server, ObjectIds.VariableTypesFolder)
self.object_types = Node(server, ObjectIds.ObjectTypesFolder)
self.namespace_array = Node(server, ObjectIds.Server_NamespaceArray)
self.opc_binary = Node(server, ObjectIds.OPCBinarySchema_TypeSystem)
def __init__(self, server):
self.root = Node(server, ObjectIds.RootFolder)
self.objects = Node(server, ObjectIds.ObjectsFolder)
self.server = Node(server, ObjectIds.Server)
self.types = Node(server, ObjectIds.TypesFolder)
self.base_object_type = Node(server, ObjectIds.BaseObjectType)
self.base_data_type = Node(server, ObjectIds.BaseDataType)
self.base_event_type = Node(server, ObjectIds.BaseEventType)
self.base_variable_type = Node(server, ObjectIds.BaseVariableType)
self.folder_type = Node(server, ObjectIds.FolderType)
self.enum_data_type = Node(server, ObjectIds.Enumeration)
self.types = Node(server, ObjectIds.TypesFolder)
self.data_types = Node(server, ObjectIds.DataTypesFolder)
self.event_types = Node(server, ObjectIds.EventTypesFolder)
self.reference_types = Node(server, ObjectIds.ReferenceTypesFolder)
self.variable_types = Node(server, ObjectIds.VariableTypesFolder)
self.object_types = Node(server, ObjectIds.ObjectTypesFolder)
self.namespace_array = Node(server, ObjectIds.Server_NamespaceArray)
self.opc_binary = Node(server, ObjectIds.OPCBinarySchema_TypeSystem)
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = addnode.ReferenceTypeId
ref.SourceNodeId = parentid
ref.TargetNodeClass = addnode.NodeClass
ref.TargetNodeId = addnode.RequestedNewNodeId
refs.append(ref)
server.add_references(refs)
descs = node_type.get_children_descriptions(includesubtypes=False) # FIXME: should be false
print("node is", rdesc.NodeId, node_type, node_type.get_children())
print("Children are: ", descs)
for rdesc in descs:
_instanciate_node(server, addnode.RequestedNewNodeId, rdesc, idx)
return Node(server, addnode.RequestedNewNodeId)
def __init__(self, server):
self.root = Node(server, ObjectIds.RootFolder)
self.objects = Node(server, ObjectIds.ObjectsFolder)
self.server = Node(server, ObjectIds.Server)
self.types = Node(server, ObjectIds.TypesFolder)
self.base_object_type = Node(server, ObjectIds.BaseObjectType)
self.base_data_type = Node(server, ObjectIds.BaseDataType)
self.base_event_type = Node(server, ObjectIds.BaseEventType)
self.base_variable_type = Node(server, ObjectIds.BaseVariableType)
self.folder_type = Node(server, ObjectIds.FolderType)
self.enum_data_type = Node(server, ObjectIds.Enumeration)
self.types = Node(server, ObjectIds.TypesFolder)
self.data_types = Node(server, ObjectIds.DataTypesFolder)
self.event_types = Node(server, ObjectIds.EventTypesFolder)
self.reference_types = Node(server, ObjectIds.ReferenceTypesFolder)
self.variable_types = Node(server, ObjectIds.VariableTypesFolder)
self.object_types = Node(server, ObjectIds.ObjectTypesFolder)
self.namespace_array = Node(server, ObjectIds.Server_NamespaceArray)
self.opc_binary = Node(server, ObjectIds.OPCBinarySchema_TypeSystem)
def _instanciate_node(server, parentid, rdesc, idx):
"""
Instanciate a new node under 'parent' using a type
"""
print("Instanciating: node %s in %s" % (rdesc, parentid))
addnode = ua.AddNodesItem()
addnode.RequestedNewNodeId = ua.NodeId()
addnode.BrowseName = rdesc.BrowseName
addnode.NodeClass = rdesc.NodeClass
addnode.ParentNodeId = parentid
addnode.ReferenceTypeId = ua.TwoByteNodeId(ua.ObjectIds.HasComponent)
addnode.TypeDefinition = rdesc.TypeDefinition
print("ADDNODE", addnode)
node_type = Node(server, rdesc.NodeId)
if rdesc.NodeClass in (ua.NodeClass.Object, ua.NodeClass.ObjectType):
print(node_type, " is object")
_read_and_copy_attrs(node_type, ua.ObjectAttributes(), addnode)
#_add_object_attrs(addnode, rdesc, node_type)
elif rdesc.NodeClass in (ua.NodeClass.Variable, ua.NodeClass.VariableType):
print(node_type, " is variable")
_read_and_copy_attrs(node_type, ua.VariableAttributes(), addnode)
#_add_variable_attrs(addnode, rdesc, node_type)
else:
print("Node class not supported: ", rdesc.NodeClass)
print("ADDNODE FINAL ", addnode)
server.add_nodes([addnode])
def __init__(self, server):
self.root = Node(server, ObjectIds.RootFolder)
self.objects = Node(server, ObjectIds.ObjectsFolder)
self.server = Node(server, ObjectIds.Server)
self.types = Node(server, ObjectIds.TypesFolder)
self.base_object_type = Node(server, ObjectIds.BaseObjectType)
self.base_data_type = Node(server, ObjectIds.BaseDataType)
self.base_event_type = Node(server, ObjectIds.BaseEventType)
self.base_variable_type = Node(server, ObjectIds.BaseVariableType)
self.folder_type = Node(server, ObjectIds.FolderType)
self.enum_data_type = Node(server, ObjectIds.Enumeration)
self.types = Node(server, ObjectIds.TypesFolder)
self.data_types = Node(server, ObjectIds.DataTypesFolder)
self.event_types = Node(server, ObjectIds.EventTypesFolder)
self.reference_types = Node(server, ObjectIds.ReferenceTypesFolder)
self.variable_types = Node(server, ObjectIds.VariableTypesFolder)
self.object_types = Node(server, ObjectIds.ObjectTypesFolder)
self.namespace_array = Node(server, ObjectIds.Server_NamespaceArray)
self.opc_binary = Node(server, ObjectIds.OPCBinarySchema_TypeSystem)
def _subscribe(self, node=None):
if not isinstance(node, Node):
node = self.window.get_current_node()
if node is None:
return
if node in self._subscribed_nodes:
logger.warning("allready subscribed to node: %s ", node)
return
self.model.setHorizontalHeaderLabels(["DisplayName", "Value", "Timestamp"])
text = str(node.get_display_name().Text)
row = [QStandardItem(text), QStandardItem("No Data yet"), QStandardItem("")]
row[0].setData(node)
self.model.appendRow(row)
self._subscribed_nodes.append(node)
self.window.ui.subDockWidget.raise_()
try:
self.uaclient.subscribe_datachange(node, self._subhandler)
except Exception as ex: