Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
04d1e6a7
Commit
04d1e6a7
authored
Jul 18, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix typo, add test for enum, move test from server to common
parent
0ddc2c6b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
23 deletions
+36
-23
opcua/common/instantiate.py
opcua/common/instantiate.py
+3
-3
opcua/common/manage_nodes.py
opcua/common/manage_nodes.py
+8
-9
tests/tests_common.py
tests/tests_common.py
+24
-0
tests/tests_server.py
tests/tests_server.py
+1
-11
No files found.
opcua/common/instantiate.py
View file @
04d1e6a7
"""
instantiate a node from a node type.
Can also be used to duplicate a node tree
Instantiate a new node and its child nodes from a node type.
"""
...
...
@@ -12,6 +11,8 @@ def instantiate(parent, node_type, nodeid=None, bname=None, idx=0):
"""
instantiate a node type under a parent node.
nodeid and browse name of new node can be specified, or just namespace index
If they exists children of the node type, such as components, variables and
properties are also instantiated
"""
results
=
node_type
.
get_attributes
([
ua
.
AttributeIds
.
NodeClass
,
ua
.
AttributeIds
.
BrowseName
,
ua
.
AttributeIds
.
DisplayName
])
...
...
@@ -22,7 +23,6 @@ def instantiate(parent, node_type, nodeid=None, bname=None, idx=0):
rdesc
.
BrowseName
=
qname
rdesc
.
DisplayName
=
dname
rdesc
.
NodeClass
=
nclass
if
parent
.
get_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
FolderType
):
rdesc
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
Organizes
)
else
:
...
...
opcua/common/manage_nodes.py
View file @
04d1e6a7
...
...
@@ -97,7 +97,7 @@ def create_variable_type(parent, nodeid, bname, datatype):
addnode
.
BrowseName
=
qname
addnode
.
NodeClass
=
ua
.
NodeClass
.
Variable
addnode
.
ParentNodeId
=
parent
.
nodeid
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSub
T
ype
)
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSub
t
ype
)
attrs
=
ua
.
VariableTypeAttributes
()
attrs
.
Description
=
ua
.
LocalizedText
(
qname
.
Name
)
attrs
.
DisplayName
=
ua
.
LocalizedText
(
qname
.
Name
)
...
...
@@ -126,7 +126,7 @@ def create_reference_type(parent, nodeid, bname):
addnode
.
BrowseName
=
qname
addnode
.
NodeClass
=
ua
.
NodeClass
.
Variable
addnode
.
ParentNodeId
=
parent
.
nodeid
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSub
T
ype
)
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSub
t
ype
)
attrs
=
ua
.
ReferenceTypeAttributes
()
attrs
.
IsAbstract
=
False
attrs
.
Description
=
ua
.
LocalizedText
(
qname
.
Name
)
...
...
@@ -260,7 +260,7 @@ def _create_variable_type(server, parentnodeid, nodeid, qname, datatype, value=N
addnode
.
BrowseName
=
qname
addnode
.
NodeClass
=
ua
.
NodeClass
.
VariableType
addnode
.
ParentNodeId
=
parentnodeid
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSub
T
ype
)
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSub
t
ype
)
#addnode.TypeDefinition = ua.NodeId(ua.ObjectIds.BaseDataVariableType)
attrs
=
ua
.
VariableTypeAttributes
()
attrs
.
Description
=
ua
.
LocalizedText
(
qname
.
Name
)
...
...
@@ -284,7 +284,7 @@ def _create_variable_type(server, parentnodeid, nodeid, qname, datatype, value=N
return
results
[
0
].
AddedNodeId
def
create_data_type
(
server
,
parentnodeid
,
nodeid
,
q
name
,
description
=
None
):
def
create_data_type
(
parent
,
nodeid
,
b
name
,
description
=
None
):
"""
Create a new data type to be used in new variables, etc ..
arguments are nodeid, browsename
...
...
@@ -296,8 +296,8 @@ def create_data_type(server, parentnodeid, nodeid, qname, description=None):
addnode
.
RequestedNewNodeId
=
nodeid
addnode
.
BrowseName
=
qname
addnode
.
NodeClass
=
ua
.
NodeClass
.
DataType
addnode
.
ParentNodeId
=
parentnodeid
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSub
T
ype
)
addnode
.
ParentNodeId
=
parent
.
nodeid
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSub
t
ype
)
#addnode.TypeDefinition = ua.NodeId(ua.ObjectIds.BaseDataVariableType) # No type definition for types
attrs
=
ua
.
DataTypeAttributes
()
if
description
is
None
:
...
...
@@ -307,12 +307,11 @@ def create_data_type(server, parentnodeid, nodeid, qname, description=None):
attrs
.
DisplayName
=
ua
.
LocalizedText
(
qname
.
Name
)
attrs
.
WriteMask
=
0
attrs
.
UserWriteMask
=
0
attrs
.
Historizing
=
0
attrs
.
IsAbstract
=
False
# True mean they cannot be instanciated
addnode
.
NodeAttributes
=
attrs
results
=
server
.
add_nodes
([
addnode
])
results
=
parent
.
server
.
add_nodes
([
addnode
])
results
[
0
].
StatusCode
.
check
()
return
results
[
0
].
AddedNodeId
return
node
.
Node
(
parent
.
server
,
results
[
0
].
AddedNodeId
)
def
_create_method
(
parent
,
nodeid
,
qname
,
callback
,
inputs
,
outputs
):
...
...
tests/tests_common.py
View file @
04d1e6a7
...
...
@@ -564,4 +564,28 @@ class CommonTests(object):
self
.
assertNotEqual
(
prop
.
nodeid
,
prop_t
.
nodeid
)
def
test_variable_with_datatype
(
self
):
o
=
self
.
opc
.
get_objects_node
()
v1
=
o
.
add_variable
(
3
,
'VariableEnumType1'
,
ua
.
ApplicationType
.
ClientAndServer
,
datatype
=
ua
.
NodeId
(
ua
.
ObjectIds
.
ApplicationType
))
tp1
=
v1
.
get_data_type
()
self
.
assertEqual
(
ua
.
NodeId
(
ua
.
ObjectIds
.
ApplicationType
),
tp1
)
v2
=
o
.
add_variable
(
3
,
'VariableEnumType2'
,
ua
.
ApplicationType
.
ClientAndServer
,
datatype
=
ua
.
NodeId
(
ua
.
ObjectIds
.
ApplicationType
)
)
tp2
=
v2
.
get_data_type
()
self
.
assertEqual
(
ua
.
NodeId
(
ua
.
ObjectIds
.
ApplicationType
),
tp2
)
def
test_enum
(
self
):
# create enum type
enums
=
self
.
opc
.
get_root_node
().
get_child
([
"0:Types"
,
"0:DataTypes"
,
"0:BaseDataType"
,
"0:Enumeration"
])
myenum_type
=
enums
.
add_data_type
(
0
,
"MyEnum"
)
es
=
myenum_type
.
add_variable
(
0
,
"EnumStrings"
,
[
"String0"
,
"String1"
,
"String2"
],
ua
.
VariantType
.
LocalizedText
)
#es.set_value_rank(1)
# instantiate
o
=
self
.
opc
.
get_objects_node
()
myvar
=
o
.
add_variable
(
2
,
"MyEnumVar"
,
"String1"
,
ua
.
VariantType
.
LocalizedText
,
datatype
=
myenum_type
.
nodeid
)
#myvar.set_writable(True)
# tests
self
.
assertEqual
(
myvar
.
get_data_type
(),
myenum_type
.
nodeid
)
myvar
.
set_value
(
"String2"
,
ua
.
VariantType
.
LocalizedText
)
tests/tests_server.py
View file @
04d1e6a7
...
...
@@ -16,7 +16,7 @@ from opcua import uamethod
from
opcua.common.event_objects
import
BaseEvent
,
AuditEvent
port_num
=
485
1
40
port_num
=
48540
port_discovery
=
48550
...
...
@@ -363,16 +363,6 @@ class TestServer(unittest.TestCase, CommonTests, SubscriptionTests):
self
.
assertEqual
(
evgen
.
event
.
PropertyNum
,
None
)
self
.
assertEqual
(
evgen
.
event
.
PropertyString
,
None
)
def
test_add_variable_with_datatype
(
self
):
o
=
self
.
opc
.
get_objects_node
()
v1
=
o
.
add_variable
(
3
,
'VariableEnumType1'
,
ua
.
ApplicationType
.
ClientAndServer
,
datatype
=
ua
.
NodeId
(
ua
.
ObjectIds
.
ApplicationType
))
tp1
=
v1
.
get_data_type
()
self
.
assertEqual
(
ua
.
NodeId
(
ua
.
ObjectIds
.
ApplicationType
),
tp1
)
v2
=
o
.
add_variable
(
3
,
'VariableEnumType2'
,
ua
.
ApplicationType
.
ClientAndServer
,
datatype
=
ua
.
NodeId
(
ua
.
ObjectIds
.
ApplicationType
)
)
tp2
=
v2
.
get_data_type
()
self
.
assertEqual
(
ua
.
NodeId
(
ua
.
ObjectIds
.
ApplicationType
),
tp2
)
def
test_context_manager
(
self
):
""" Context manager calls start() and stop()
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment