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
01d43e8a
Commit
01d43e8a
authored
Dec 31, 2020
by
oroulet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more sync methods and fix typo in builder
parent
7f8a84b1
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
85 additions
and
38 deletions
+85
-38
asyncua/common/copy_node_util.py
asyncua/common/copy_node_util.py
+2
-2
asyncua/common/manage_nodes.py
asyncua/common/manage_nodes.py
+1
-1
asyncua/common/node.py
asyncua/common/node.py
+1
-1
asyncua/common/type_dictionary_builder.py
asyncua/common/type_dictionary_builder.py
+0
-0
asyncua/sync.py
asyncua/sync.py
+57
-6
examples/server-create-custom-structures.py
examples/server-create-custom-structures.py
+1
-3
tests/test_common.py
tests/test_common.py
+12
-12
tests/test_custom_structures.py
tests/test_custom_structures.py
+10
-12
tests/test_server.py
tests/test_server.py
+1
-1
No files found.
asyncua/common/copy_node_util.py
View file @
01d43e8a
...
...
@@ -51,11 +51,11 @@ async def _rdesc_from_node(parent, node):
rdesc
.
BrowseName
=
qname
rdesc
.
DisplayName
=
dname
rdesc
.
NodeClass
=
nclass
if
await
parent
.
get
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
FolderType
):
if
await
parent
.
read
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
FolderType
):
rdesc
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
Organizes
)
else
:
rdesc
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasComponent
)
typedef
=
await
node
.
get
_type_definition
()
typedef
=
await
node
.
read
_type_definition
()
if
typedef
:
rdesc
.
TypeDefinition
=
typedef
return
rdesc
...
...
asyncua/common/manage_nodes.py
View file @
01d43e8a
...
...
@@ -177,7 +177,7 @@ async def _create_object(server, parentnodeid, nodeid, qname, objecttype):
addnode
.
RequestedNewNodeId
=
nodeid
addnode
.
BrowseName
=
qname
addnode
.
ParentNodeId
=
parentnodeid
if
await
make_node
(
server
,
parentnodeid
).
get
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
FolderType
):
if
await
make_node
(
server
,
parentnodeid
).
read
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
FolderType
):
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
Organizes
)
else
:
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasComponent
)
...
...
asyncua/common/node.py
View file @
01d43e8a
...
...
@@ -422,7 +422,7 @@ class Node:
nodes
.
append
(
node
)
return
nodes
async
def
get
_type_definition
(
self
):
async
def
read
_type_definition
(
self
):
"""
returns type definition of the node.
"""
...
...
asyncua/common/type_dictionary_buider.py
→
asyncua/common/type_dictionary_bui
l
der.py
View file @
01d43e8a
File moved
asyncua/sync.py
View file @
01d43e8a
...
...
@@ -9,8 +9,7 @@ from asyncua import ua
from
asyncua
import
client
from
asyncua
import
server
from
asyncua
import
common
from
asyncua.common
import
node
from
asyncua.common
import
subscription
,
shortcuts
from
asyncua.common
import
node
,
subscription
,
shortcuts
,
xmlexporter
,
type_dictionary_builder
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -117,6 +116,16 @@ def data_type_to_variant_type(dtype_node):
pass
@
syncfunc
(
aio_func
=
common
.
copy_node_util
.
copy_node
)
def
copy_node
(
parent
,
node
,
nodeid
=
None
,
recursive
=
True
):
pass
@
syncfunc
(
aio_func
=
common
.
instantiate_util
.
instantiate
)
def
instantiate
(
parent
,
node_type
,
nodeid
=
None
,
bname
=
None
,
dname
=
None
,
idx
=
0
,
instantiate_optional
=
True
):
pass
class
_SubHandler
:
def
__init__
(
self
,
tloop
,
sync_handler
):
self
.
tloop
=
tloop
...
...
@@ -246,6 +255,10 @@ class Server:
def
register_namespace
(
self
,
url
):
pass
@
syncmethod
async
def
get_namespace_array
(
self
):
pass
@
syncmethod
def
start
(
self
):
pass
...
...
@@ -334,6 +347,10 @@ class Node:
nodeid
=
property
(
__get_nodeid
,
__set_nodeid
)
@
syncmethod
def
read_type_definition
(
self
):
pass
@
syncmethod
def
get_parent
(
self
):
pass
...
...
@@ -411,6 +428,10 @@ class Node:
def
add_method
(
self
,
*
args
):
pass
@
syncmethod
def
add_data_type
(
self
,
*
args
):
pass
@
syncmethod
def
set_writable
(
self
,
writable
=
True
):
pass
...
...
@@ -467,10 +488,6 @@ class Node:
def
get_path
(
self
):
pass
@
syncmethod
def
read_node_class
(
self
):
pass
@
syncmethod
def
read_attributes
(
self
):
pass
...
...
@@ -509,3 +526,37 @@ class Subscription:
@
syncmethod
def
delete
(
self
):
pass
class
XmlExporter
:
def
__init__
(
self
,
sync_server
):
self
.
sync_server
=
sync_server
self
.
aio_obj
=
xmlexporter
.
XmlExporter
(
self
.
sync_server
.
server
)
@
syncmethod
def
build_etree
(
self
,
node_list
,
uris
=
None
):
pass
@
syncmethod
async
def
write_xml
(
self
,
xmlpath
,
pretty
=
True
):
pass
class
DataTypeDictionaryBuilder
:
def
__init__
(
self
,
server
,
idx
,
ns_urn
,
dict_name
,
dict_node_id
=
None
):
self
.
server
=
server
self
.
dict_id
=
dict_node_id
self
.
aio_obj
=
type_dictionary_builder
.
DataTypeDictonaryBuilder
(
server
,
idx
,
ns_urn
,
dict_name
,
dict_node_id
)
self
.
init
()
@
syncmethod
def
init
(
self
):
pass
@
syncmethod
def
create_data_type
(
self
,
type_name
,
nodeid
=
None
,
init
=
True
):
pass
@
syncmethod
async
def
set_dict_byte_string
(
self
):
pass
examples/server-create-custom-structures.py
View file @
01d43e8a
import
logging
import
asyncio
from
IPython
import
embed
from
asyncua
import
ua
,
Server
from
asyncua.common.type_dictionary_buider
import
DataTypeDictionaryBuilder
from
asyncua.common.type_dictionary_bui
l
der
import
DataTypeDictionaryBuilder
async
def
main
():
...
...
tests/test_common.py
View file @
01d43e8a
...
...
@@ -745,16 +745,16 @@ async def test_add_node_with_type(opc):
f
=
await
objects
.
add_folder
(
3
,
'MyFolder_TypeTest'
)
o
=
await
f
.
add_object
(
3
,
'MyObject1'
,
ua
.
ObjectIds
.
BaseObjectType
)
assert
ua
.
ObjectIds
.
BaseObjectType
==
(
await
o
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
BaseObjectType
==
(
await
o
.
read
_type_definition
()).
Identifier
o
=
await
f
.
add_object
(
3
,
'MyObject2'
,
ua
.
NodeId
(
ua
.
ObjectIds
.
BaseObjectType
,
0
))
assert
ua
.
ObjectIds
.
BaseObjectType
==
(
await
o
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
BaseObjectType
==
(
await
o
.
read
_type_definition
()).
Identifier
base_otype
=
opc
.
opc
.
get_node
(
ua
.
ObjectIds
.
BaseObjectType
)
custom_otype
=
await
base_otype
.
add_object_type
(
2
,
'MyFooObjectType2'
)
o
=
await
f
.
add_object
(
3
,
'MyObject3'
,
custom_otype
.
nodeid
)
assert
custom_otype
.
nodeid
.
Identifier
==
(
await
o
.
get
_type_definition
()).
Identifier
assert
custom_otype
.
nodeid
.
Identifier
==
(
await
o
.
read
_type_definition
()).
Identifier
references
=
await
o
.
get_references
(
refs
=
ua
.
ObjectIds
.
HasTypeDefinition
,
direction
=
ua
.
BrowseDirection
.
Forward
)
assert
1
==
len
(
references
)
...
...
@@ -774,7 +774,7 @@ async def test_references_for_added_nodes(opc):
)
assert
objects
in
nodes
assert
objects
==
await
o
.
get_parent
()
assert
ua
.
ObjectIds
.
BaseObjectType
==
(
await
o
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
BaseObjectType
==
(
await
o
.
read
_type_definition
()).
Identifier
assert
[]
==
await
o
.
get_references
(
ua
.
ObjectIds
.
HasModellingRule
)
o2
=
await
o
.
add_object
(
3
,
'MySecondObject'
)
...
...
@@ -787,7 +787,7 @@ async def test_references_for_added_nodes(opc):
)
assert
o
in
nodes
assert
o
==
await
o2
.
get_parent
()
assert
ua
.
ObjectIds
.
BaseObjectType
==
(
await
o2
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
BaseObjectType
==
(
await
o2
.
read
_type_definition
()).
Identifier
assert
[]
==
await
o2
.
get_references
(
ua
.
ObjectIds
.
HasModellingRule
)
v
=
await
o
.
add_variable
(
3
,
'MyVariable'
,
6
)
...
...
@@ -800,7 +800,7 @@ async def test_references_for_added_nodes(opc):
)
assert
o
in
nodes
assert
o
==
await
v
.
get_parent
()
assert
ua
.
ObjectIds
.
BaseDataVariableType
==
(
await
v
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
BaseDataVariableType
==
(
await
v
.
read
_type_definition
()).
Identifier
assert
[]
==
await
v
.
get_references
(
ua
.
ObjectIds
.
HasModellingRule
)
p
=
await
o
.
add_property
(
3
,
'MyProperty'
,
2
)
...
...
@@ -813,7 +813,7 @@ async def test_references_for_added_nodes(opc):
)
assert
o
in
nodes
assert
o
==
await
p
.
get_parent
()
assert
ua
.
ObjectIds
.
PropertyType
==
(
await
p
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
PropertyType
==
(
await
p
.
read
_type_definition
()).
Identifier
assert
[]
==
await
p
.
get_references
(
ua
.
ObjectIds
.
HasModellingRule
)
m
=
await
objects
.
get_child
(
"2:ServerMethod"
)
...
...
@@ -865,7 +865,7 @@ async def test_copy_node(opc):
assert
4
==
len
(
await
mydevice
.
get_children
())
obj
=
await
mydevice
.
get_child
([
"0:controller"
])
prop
=
await
mydevice
.
get_child
([
"0:controller"
,
"0:state"
])
assert
ua
.
ObjectIds
.
PropertyType
==
(
await
prop
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
PropertyType
==
(
await
prop
.
read
_type_definition
()).
Identifier
assert
"Running"
==
await
prop
.
read_value
()
assert
prop
.
nodeid
!=
prop_t
.
nodeid
...
...
@@ -898,7 +898,7 @@ async def test_instantiate_1(opc):
mydevice
=
nodes
[
0
]
assert
ua
.
NodeClass
.
Object
==
await
mydevice
.
read_node_class
()
assert
dev_t
.
nodeid
==
await
mydevice
.
get
_type_definition
()
assert
dev_t
.
nodeid
==
await
mydevice
.
read
_type_definition
()
obj
=
await
mydevice
.
get_child
([
"0:controller"
])
prop
=
await
mydevice
.
get_child
([
"0:controller"
,
"0:state"
])
with
pytest
.
raises
(
ua
.
UaError
):
...
...
@@ -906,7 +906,7 @@ async def test_instantiate_1(opc):
with
pytest
.
raises
(
ua
.
UaError
):
await
mydevice
.
get_child
([
"0:controller"
,
"0:model"
])
assert
ua
.
ObjectIds
.
PropertyType
==
(
await
prop
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
PropertyType
==
(
await
prop
.
read
_type_definition
()).
Identifier
assert
"Running"
==
await
prop
.
read_value
()
assert
prop
.
nodeid
!=
prop_t
.
nodeid
...
...
@@ -938,12 +938,12 @@ async def test_instantiate_string_nodeid(opc):
mydevice
=
nodes
[
0
]
assert
ua
.
NodeClass
.
Object
==
await
mydevice
.
read_node_class
()
assert
dev_t
.
nodeid
==
await
mydevice
.
get
_type_definition
()
assert
dev_t
.
nodeid
==
await
mydevice
.
read
_type_definition
()
obj
=
await
mydevice
.
get_child
([
"0:controller"
])
obj_nodeid_ident
=
obj
.
nodeid
.
Identifier
prop
=
await
mydevice
.
get_child
([
"0:controller"
,
"0:state"
])
assert
"InstDevice.controller"
==
obj_nodeid_ident
assert
ua
.
ObjectIds
.
PropertyType
==
(
await
prop
.
get
_type_definition
()).
Identifier
assert
ua
.
ObjectIds
.
PropertyType
==
(
await
prop
.
read
_type_definition
()).
Identifier
assert
"Running"
==
await
prop
.
read_value
()
assert
prop
.
nodeid
!=
prop_t
.
nodeid
await
opc
.
opc
.
delete_nodes
([
dev_t
])
...
...
tests/test_custom_structures.py
View file @
01d43e8a
import
unittest
import
logging
import
xml.etree.ElementTree
as
Et
import
pytest
from
asyncua
import
ua
,
Server
import
asyncua.common.type_dictionary_buider
from
asyncua.common.type_dictionary_buider
import
OPCTypeDictionaryBuilder
,
DataTypeDictionaryBuilder
from
asyncua.common.type_dictionary_buider
import
get_ua_class
,
StructNode
from
asyncua
import
ua
import
asyncua.common.type_dictionary_bui
l
der
from
asyncua.common.type_dictionary_bui
l
der
import
OPCTypeDictionaryBuilder
,
DataTypeDictionaryBuilder
from
asyncua.common.type_dictionary_bui
l
der
import
get_ua_class
,
StructNode
port_num
=
48540
ns_urn
=
'http://test.freeopcua.github.io'
...
...
@@ -17,12 +15,12 @@ pytestmark = pytest.mark.asyncio
def
to_camel_case
(
name
):
func
=
getattr
(
asyncua
.
common
.
type_dictionary_buider
,
'_to_camel_case'
)
func
=
getattr
(
asyncua
.
common
.
type_dictionary_bui
l
der
,
'_to_camel_case'
)
return
func
(
name
)
def
reference_generator
(
source_id
,
target_id
,
reference_type
,
is_forward
=
True
):
func
=
getattr
(
asyncua
.
common
.
type_dictionary_buider
,
'_reference_generator'
)
func
=
getattr
(
asyncua
.
common
.
type_dictionary_bui
l
der
,
'_reference_generator'
)
return
func
(
source_id
,
target_id
,
reference_type
,
is_forward
)
...
...
@@ -46,7 +44,7 @@ async def _srv(server):
srv
.
idx
=
await
srv
.
srv
.
register_namespace
(
ns_urn
)
yield
srv
@
pytest
.
fixture
async
def
srv
(
_srv
):
_srv
.
test_etree
=
set_up_test_tree
()
...
...
@@ -186,7 +184,7 @@ async def test_data_type_dict_add_dictionary(srv):
assert
await
dict_node
.
read_node_class
()
==
ua
.
NodeClass
.
Variable
assert
(
await
dict_node
.
get_parent
()).
nodeid
==
ua
.
NodeId
(
ua
.
ObjectIds
.
OPCBinarySchema_TypeSystem
,
0
)
assert
ua
.
NodeId
(
ua
.
ObjectIds
.
HasComponent
,
0
)
==
(
await
dict_node
.
get_references
(
refs
=
ua
.
ObjectIds
.
HasComponent
))[
0
].
ReferenceTypeId
assert
await
dict_node
.
get
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
DataTypeDictionaryType
,
0
)
assert
await
dict_node
.
read
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
DataTypeDictionaryType
,
0
)
assert
await
dict_node
.
read_display_name
()
==
ua
.
LocalizedText
(
dict_name
)
assert
await
dict_node
.
read_data_type
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
ByteString
)
assert
await
dict_node
.
read_value_rank
()
==
-
1
...
...
@@ -211,7 +209,7 @@ async def test_data_type_dict_create_data_type(srv):
assert
await
desc_node
.
read_node_class
()
==
ua
.
NodeClass
.
Variable
assert
(
await
desc_node
.
get_parent
()).
nodeid
==
srv
.
dict_builder
.
dict_id
assert
ua
.
NodeId
(
ua
.
ObjectIds
.
HasComponent
,
0
)
==
(
await
desc_node
.
get_references
(
refs
=
ua
.
ObjectIds
.
HasComponent
))[
0
].
ReferenceTypeId
assert
await
desc_node
.
get
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
DataTypeDescriptionType
,
0
)
assert
await
desc_node
.
read
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
DataTypeDescriptionType
,
0
)
assert
await
desc_node
.
read_display_name
()
==
ua
.
LocalizedText
(
type_name
)
assert
await
desc_node
.
read_data_type
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
String
)
...
...
@@ -224,7 +222,7 @@ async def test_data_type_dict_create_data_type(srv):
assert
await
obj_node
.
read_node_class
()
==
ua
.
NodeClass
.
Object
assert
(
await
obj_node
.
get_references
(
refs
=
ua
.
ObjectIds
.
HasEncoding
))[
0
].
NodeId
==
type_node
.
nodeid
assert
ua
.
NodeId
(
ua
.
ObjectIds
.
HasEncoding
,
0
)
==
(
await
obj_node
.
get_references
(
refs
=
ua
.
ObjectIds
.
HasEncoding
))[
0
].
ReferenceTypeId
assert
await
obj_node
.
get
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
DataTypeEncodingType
,
0
)
assert
await
obj_node
.
read
_type_definition
()
==
ua
.
NodeId
(
ua
.
ObjectIds
.
DataTypeEncodingType
,
0
)
assert
await
obj_node
.
read_display_name
()
==
ua
.
LocalizedText
(
'Default Binary'
)
assert
len
(
await
obj_node
.
read_event_notifier
())
==
0
...
...
tests/test_server.py
View file @
01d43e8a
...
...
@@ -171,7 +171,7 @@ async def test_references_for_added_nodes_method(server):
includesubtypes
=
False
)
assert
objects
in
nodes
assert
await
o
.
get_parent
()
==
objects
assert
(
await
o
.
get
_type_definition
()).
Identifier
==
ua
.
ObjectIds
.
BaseObjectType
assert
(
await
o
.
read
_type_definition
()).
Identifier
==
ua
.
ObjectIds
.
BaseObjectType
@
uamethod
def
callback
(
parent
):
...
...
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