Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_server_node(self):
node = self.opc.get_server_node()
self.assertEqual(ua.QualifiedName('Server', 0), node.get_browse_name())
def test_add_string_array_variable(self):
objects = self.opc.get_objects_node()
v = objects.add_variable('ns=3;s=stringarrayid;', '9:stringarray', ['l', 'b'])
nid = ua.NodeId('stringarrayid', 3)
qn = ua.QualifiedName('stringarray', 9)
self.assertEqual(nid, v.nodeid)
self.assertEqual(qn, v.get_browse_name())
val = v.get_value()
self.assertEqual(['l', 'b'], val)
def test_add_string_array_variable(self):
objects = self.opc.get_objects_node()
v = objects.add_variable('ns=3;s=stringarrayid;', '9:stringarray', ['l', 'b'])
nid = ua.NodeId('stringarrayid', 3)
qn = ua.QualifiedName('stringarray', 9)
self.assertEqual(nid, v.nodeid)
self.assertEqual(qn, v.get_browse_name())
val = v.get_value()
self.assertEqual(['l', 'b'], val)
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = ua.NodeId.from_string("i=39")
ref.SourceNodeId = ua.NodeId.from_string("i=591")
ref.TargetNodeClass = ua.NodeClass.DataType
ref.TargetNodeId = ua.NodeId.from_string("i=7935")
refs.append(ref)
server.add_references(refs)
node = ua.AddNodesItem()
node.RequestedNewNodeId = ua.NodeId.from_string("i=594")
node.BrowseName = ua.QualifiedName.from_string("Default Binary")
node.NodeClass = ua.NodeClass.Object
node.ParentNodeId = ua.NodeId.from_string("i=592")
node.ReferenceTypeId = ua.NodeId.from_string("i=38")
node.TypeDefinition = ua.NodeId.from_string("i=76")
attrs = ua.ObjectAttributes()
attrs.DisplayName = ua.LocalizedText("Default Binary")
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = ua.NodeId.from_string("i=39")
ref.SourceNodeId = ua.NodeId.from_string("i=594")
ref.TargetNodeClass = ua.NodeClass.DataType
ref.TargetNodeId = ua.NodeId.from_string("i=7938")
# create data type node
dt_node = ua.AddNodesItem()
dt_node.RequestedNewNodeId = data_type_node_id
dt_node.BrowseName = ua.QualifiedName(name, self._idx)
dt_node.NodeClass = ua.NodeClass.DataType
dt_node.ParentNodeId = ua.NodeId(ua.ObjectIds.Structure, 0)
dt_node.ReferenceTypeId = ua.NodeId(ua.ObjectIds.HasSubtype, 0)
dt_attributes = ua.DataTypeAttributes()
dt_attributes.DisplayName = ua.LocalizedText(type_name)
dt_node.NodeAttributes = dt_attributes
# create description node
desc_node = ua.AddNodesItem()
desc_node.RequestedNewNodeId = description_node_id
desc_node.BrowseName = ua.QualifiedName(name, self._idx)
desc_node.NodeClass = ua.NodeClass.Variable
desc_node.ParentNodeId = self.dict_id
desc_node.ReferenceTypeId = ua.NodeId(ua.ObjectIds.HasComponent, 0)
desc_node.TypeDefinition = ua.NodeId(ua.ObjectIds.DataTypeDescriptionType, 0)
desc_attributes = ua.VariableAttributes()
desc_attributes.DisplayName = ua.LocalizedText(type_name)
desc_attributes.DataType = ua.NodeId(ua.ObjectIds.String)
desc_attributes.Value = ua.Variant(name, ua.VariantType.String)
desc_attributes.ValueRank = -1
desc_node.NodeAttributes = desc_attributes
# create object node which the loaded python class should link to
obj_node = ua.AddNodesItem()
obj_node.RequestedNewNodeId = bind_obj_node_id
obj_node.BrowseName = ua.QualifiedName('Default Binary', 0)
obj_node.NodeClass = ua.NodeClass.Object
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = ua.NodeId.from_string("i=39")
ref.SourceNodeId = ua.NodeId.from_string("i=542")
ref.TargetNodeClass = ua.NodeClass.DataType
ref.TargetNodeId = ua.NodeId.from_string("i=12721")
refs.append(ref)
server.add_references(refs)
node = ua.AddNodesItem()
node.RequestedNewNodeId = ua.NodeId.from_string("i=333")
node.BrowseName = ua.QualifiedName.from_string("Default Binary")
node.NodeClass = ua.NodeClass.Object
node.ParentNodeId = ua.NodeId.from_string("i=331")
node.ReferenceTypeId = ua.NodeId.from_string("i=38")
node.TypeDefinition = ua.NodeId.from_string("i=76")
attrs = ua.ObjectAttributes()
attrs.DisplayName = ua.LocalizedText("Default Binary")
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = ua.NodeId.from_string("i=39")
ref.SourceNodeId = ua.NodeId.from_string("i=333")
ref.TargetNodeClass = ua.NodeClass.DataType
ref.TargetNodeId = ua.NodeId.from_string("i=7686")
def _add_dictionary(self, name):
dictionary_node_id = self._nodeid_generator()
node = ua.AddNodesItem()
node.RequestedNewNodeId = dictionary_node_id
node.BrowseName = ua.QualifiedName(name, self._idx)
node.NodeClass = ua.NodeClass.Variable
node.ParentNodeId = ua.NodeId(ua.ObjectIds.OPCBinarySchema_TypeSystem, 0)
node.ReferenceTypeId = ua.NodeId(ua.ObjectIds.HasComponent, 0)
node.TypeDefinition = ua.NodeId(ua.ObjectIds.DataTypeDictionaryType, 0)
attrs = ua.VariableAttributes()
attrs.DisplayName = ua.LocalizedText(name)
attrs.DataType = ua.NodeId(ua.ObjectIds.ByteString)
# Value should be set after all data types created by calling set_dict_byte_string
attrs.Value = ua.Variant(None, ua.VariantType.Null)
attrs.ValueRank = -1
node.NodeAttributes = attrs
self._session_server.add_nodes([node])
return dictionary_node_id
ref.SourceNodeId = ua.NodeId.from_string("i=12089")
ref.TargetNodeClass = ua.NodeClass.DataType
ref.TargetNodeId = ua.NodeId.from_string("i=12091")
refs.append(ref)
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = ua.NodeId.from_string("i=40")
ref.SourceNodeId = ua.NodeId.from_string("i=12089")
ref.TargetNodeClass = ua.NodeClass.DataType
ref.TargetNodeId = ua.NodeId.from_string("i=76")
refs.append(ref)
server.add_references(refs)
node = ua.AddNodesItem()
node.RequestedNewNodeId = ua.NodeId.from_string("i=12090")
node.BrowseName = ua.QualifiedName.from_string("Default Binary")
node.NodeClass = ua.NodeClass.Object
node.ParentNodeId = ua.NodeId.from_string("i=12080")
node.ReferenceTypeId = ua.NodeId.from_string("i=38")
node.TypeDefinition = ua.NodeId.from_string("i=76")
attrs = ua.ObjectAttributes()
attrs.DisplayName = ua.LocalizedText("Default Binary")
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = False
ref.ReferenceTypeId = ua.NodeId.from_string("i=38")
ref.SourceNodeId = ua.NodeId.from_string("i=12090")
ref.TargetNodeClass = ua.NodeClass.DataType
ref.TargetNodeId = ua.NodeId.from_string("i=12080")
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = NumericNodeId(40, 0)
ref.SourceNodeId = NumericNodeId(11305, 0)
ref.TargetNodeClass = NodeClass.DataType
ref.TargetNodeId = NumericNodeId(2340, 0)
refs.append(ref)
server.add_references(refs)
node = ua.AddNodesItem()
node.RequestedNewNodeId = NumericNodeId(11306, 0)
node.BrowseName = QualifiedName('MaximumActualTime2', 0)
node.NodeClass = NodeClass.Object
node.TypeDefinition = NumericNodeId(2340, 0)
attrs = ua.ObjectAttributes()
attrs.Description = LocalizedText("Retrieve the maximum value with the actual timestamp including the Simple Bounding Values.")
attrs.DisplayName = LocalizedText("MaximumActualTime2")
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = NumericNodeId(40, 0)
ref.SourceNodeId = NumericNodeId(11306, 0)
ref.TargetNodeClass = NodeClass.DataType
ref.TargetNodeId = NumericNodeId(2340, 0)
refs.append(ref)
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = NumericNodeId(40, 0)
ref.SourceNodeId = NumericNodeId(11428, 0)
ref.TargetNodeClass = NodeClass.DataType
ref.TargetNodeId = NumericNodeId(2340, 0)
refs.append(ref)
server.add_references(refs)
node = ua.AddNodesItem()
node.RequestedNewNodeId = NumericNodeId(11429, 0)
node.BrowseName = QualifiedName('VariancePopulation', 0)
node.NodeClass = NodeClass.Object
node.TypeDefinition = NumericNodeId(2340, 0)
attrs = ua.ObjectAttributes()
attrs.Description = LocalizedText("Retrieve the variance for the interval as calculated by the StandardDeviationPopulation which includes Simple Bounding Values.")
attrs.DisplayName = LocalizedText("VariancePopulation")
attrs.EventNotifier = 0
node.NodeAttributes = attrs
server.add_nodes([node])
refs = []
ref = ua.AddReferencesItem()
ref.IsForward = True
ref.ReferenceTypeId = NumericNodeId(40, 0)
ref.SourceNodeId = NumericNodeId(11429, 0)
ref.TargetNodeClass = NodeClass.DataType
ref.TargetNodeId = NumericNodeId(2340, 0)
refs.append(ref)