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
9d77d16a
Commit
9d77d16a
authored
Jan 01, 2021
by
oroulet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sync methods necessary for uamodeler
parent
01d43e8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
14 deletions
+48
-14
asyncua/sync.py
asyncua/sync.py
+41
-13
tests/test_sync.py
tests/test_sync.py
+7
-1
No files found.
asyncua/sync.py
View file @
9d77d16a
...
...
@@ -63,6 +63,8 @@ def _to_async(args, kwargs):
for
idx
,
arg
in
enumerate
(
args
):
if
isinstance
(
arg
,
Node
):
args
[
idx
]
=
arg
.
aio_obj
elif
isinstance
(
arg
,
(
list
,
tuple
)):
args
[
idx
]
=
_to_async
(
arg
,
{})[
0
]
for
k
,
v
in
kwargs
.
items
():
if
isinstance
(
v
,
Node
):
kwargs
[
k
]
=
v
.
aio_obj
...
...
@@ -98,7 +100,16 @@ def syncfunc(aio_func):
decorator for sync function
"""
def
decorator
(
func
,
*
args
,
**
kwargs
):
def
wrapper
(
tloop
,
*
args
,
**
kwargs
):
def
wrapper
(
*
args
,
**
kwargs
):
if
not
args
:
raise
RuntimeError
(
"first argument of function must a ThreadLoop object"
)
if
isinstance
(
args
[
0
],
ThreadLoop
):
tloop
=
args
[
0
]
args
=
list
(
args
)[
1
:]
elif
hasattr
(
args
[
0
],
"tloop"
):
tloop
=
args
[
0
].
tloop
else
:
raise
RuntimeError
(
"first argument of function must a ThreadLoop object"
)
args
,
kwargs
=
_to_async
(
args
,
kwargs
)
result
=
tloop
.
post
(
aio_func
(
*
args
,
**
kwargs
))
return
_to_sync
(
tloop
,
result
)
...
...
@@ -107,7 +118,7 @@ def syncfunc(aio_func):
@
syncfunc
(
aio_func
=
common
.
methods
.
call_method_full
)
def
call_method_full
(
tloop
,
parent
,
methodid
,
*
args
):
def
call_method_full
(
parent
,
methodid
,
*
args
):
pass
...
...
@@ -173,7 +184,7 @@ class Client:
pass
@
syncmethod
async
def
load_data_type_definitions
(
self
,
node
=
None
):
def
load_data_type_definitions
(
self
,
node
=
None
):
pass
@
syncmethod
...
...
@@ -256,7 +267,7 @@ class Server:
pass
@
syncmethod
async
def
get_namespace_array
(
self
):
def
get_namespace_array
(
self
):
pass
@
syncmethod
...
...
@@ -371,7 +382,21 @@ class Node:
def
read_display_name
(
self
):
pass
get_display_name
=
read_display_name
# legacy
@
syncmethod
def
read_data_type
(
self
):
pass
@
syncmethod
def
read_array_dimensions
(
self
):
pass
@
syncmethod
def
read_value_rank
(
self
):
pass
@
syncmethod
def
delete
(
self
):
pass
@
syncmethod
def
get_children
(
...
...
@@ -520,7 +545,7 @@ class Subscription:
pass
@
syncmethod
async
def
create_monitored_items
(
self
,
monitored_items
):
def
create_monitored_items
(
self
,
monitored_items
):
pass
@
syncmethod
...
...
@@ -530,25 +555,28 @@ class Subscription:
class
XmlExporter
:
def
__init__
(
self
,
sync_server
):
self
.
sync_server
=
sync_server
self
.
aio_obj
=
xmlexporter
.
XmlExporter
(
s
elf
.
sync_server
.
server
)
self
.
tloop
=
sync_server
.
tloop
self
.
aio_obj
=
xmlexporter
.
XmlExporter
(
s
ync_server
.
aio_obj
)
@
syncmethod
def
build_etree
(
self
,
node_list
,
uris
=
None
):
pass
@
syncmethod
async
def
write_xml
(
self
,
xmlpath
,
pretty
=
True
):
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
.
tloop
=
server
.
tloop
self
.
aio_obj
=
type_dictionary_builder
.
DataTypeDictionaryBuilder
(
server
.
aio_obj
,
idx
,
ns_urn
,
dict_name
,
dict_node_id
)
self
.
init
()
@
property
def
dict_id
(
self
):
return
self
.
aio_obj
.
dict_id
@
syncmethod
def
init
(
self
):
pass
...
...
@@ -558,5 +586,5 @@ class DataTypeDictionaryBuilder:
pass
@
syncmethod
async
def
set_dict_byte_string
(
self
):
def
set_dict_byte_string
(
self
):
pass
tests/test_sync.py
View file @
9d77d16a
...
...
@@ -2,7 +2,7 @@ from concurrent.futures import Future
import
pytest
from
asyncua.sync
import
Client
,
Server
,
ThreadLoop
,
Node
,
call_method_full
from
asyncua.sync
import
Client
,
Server
,
ThreadLoop
,
Node
,
call_method_full
,
XmlExporter
from
asyncua
import
ua
,
uamethod
...
...
@@ -126,3 +126,9 @@ def test_sync_call_meth(client, idx):
methodid
=
client
.
nodes
.
objects
.
get_child
(
f"
{
idx
}
:Divide"
)
res
=
call_method_full
(
client
.
tloop
,
client
.
nodes
.
objects
,
methodid
,
4
,
2
)
assert
res
.
OutputArguments
[
0
]
==
2
def
test_sync_xml_export
(
server
):
exp
=
XmlExporter
(
server
)
exp
.
build_etree
([
server
.
nodes
.
objects
],
uris
=
[])
exp
.
write_xml
(
"toto_test_export.xml"
)
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