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
7a949baa
Commit
7a949baa
authored
Feb 23, 2019
by
oroulet
Committed by
oroulet
Feb 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sync Node object and add small test
parent
d5b0f7b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
17 deletions
+63
-17
asyncua/server/server.py
asyncua/server/server.py
+2
-2
opcua/sync.py
opcua/sync.py
+51
-14
tests/test_sync.py
tests/test_sync.py
+10
-1
No files found.
asyncua/server/server.py
View file @
7a949baa
...
...
@@ -61,8 +61,8 @@ class Server:
:vartype nodes: Shortcuts
"""
def
__init__
(
self
,
iserver
:
InternalServer
=
None
):
self
.
loop
=
asyncio
.
get_event_loop
()
def
__init__
(
self
,
iserver
:
InternalServer
=
None
,
loop
=
None
):
self
.
loop
=
loop
or
asyncio
.
get_event_loop
()
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
endpoint
=
urlparse
(
"opc.tcp://0.0.0.0:4840/freeopcua/server/"
)
self
.
_application_uri
=
"urn:freeopcua:python:server"
...
...
opcua/sync.py
View file @
7a949baa
...
...
@@ -8,7 +8,7 @@ import logging
from
opcua
import
client
from
opcua
import
server
from
opcua.common
import
node
from
opcua.common
import
subscription
from
opcua.common
import
subscription
,
shortcuts
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -30,7 +30,6 @@ class ThreadLoop(Thread):
with
self
.
_cond
:
self
.
_cond
.
notify_all
()
self
.
loop
.
run_forever
()
print
(
"Thread ended"
)
def
stop
(
self
):
self
.
loop
.
call_soon_threadsafe
(
self
.
loop
.
stop
)
...
...
@@ -49,7 +48,6 @@ _tloop = None
def
start_thread_loop
():
print
(
"START"
)
global
_tloop
_tloop
=
ThreadLoop
()
_tloop
.
start
()
...
...
@@ -57,7 +55,6 @@ def start_thread_loop():
def
stop_thread_loop
():
print
(
"STOP"
)
global
_tloop
_tloop
.
stop
()
_tloop
.
join
()
...
...
@@ -97,20 +94,26 @@ def _get_super(func):
def
syncmethod
(
func
):
def
wrapper
(
self
,
*
args
,
**
kwargs
):
name
=
func
.
__name__
sup
=
_get_super
(
func
)
super_func
=
getattr
(
sup
,
name
)
#name = func.__name__
aio_func
=
getattr
(
self
.
aio_obj
,
func
.
__name__
)
#sup = _get_super(func)
#super_func = getattr(sup, name)
global
_tloop
result
=
_tloop
.
post
(
super_func
(
self
,
*
args
,
**
kwargs
))
result
=
_tloop
.
post
(
aio_func
(
*
args
,
**
kwargs
))
if
isinstance
(
result
,
node
.
Node
):
return
Node
(
result
)
if
isinstance
(
result
,
list
)
and
len
(
result
)
>
0
and
isinstance
(
result
[
0
],
node
.
Node
):
return
[
Node
(
i
)
for
i
in
result
]
return
result
return
wrapper
class
Client
(
client
.
Client
)
:
class
Client
:
def
__init__
(
self
,
url
:
str
,
timeout
:
int
=
4
):
global
_tloop
client
.
Client
.
__init__
(
self
,
url
,
timeout
,
loop
=
_tloop
.
loop
)
self
.
aio_obj
=
client
.
Client
(
url
,
timeout
,
loop
=
_tloop
.
loop
)
self
.
nodes
=
Shortcuts
(
self
.
aio_obj
.
uaclient
)
@
syncmethod
def
connect
(
self
):
pass
...
...
@@ -119,12 +122,26 @@ class Client(client.Client):
def
disconnect
(
self
):
pass
def
get_node
(
self
,
nodeid
):
return
Node
(
self
.
aio_obj
.
get_node
(
nodeid
))
class
Shortcuts
:
def
__init__
(
self
,
aio_server
):
self
.
aio_obj
=
shortcuts
.
Shortcuts
(
aio_server
)
for
k
,
v
in
self
.
aio_obj
.
__dict__
.
items
():
setattr
(
self
,
k
,
Node
(
v
))
class
Server
(
server
.
Server
)
:
class
Server
:
def
__init__
(
self
,
shelf_file
=
None
):
global
_tloop
server
.
Server
.
__init__
(
self
)
_tloop
.
post
(
self
.
init
(
shelf_file
))
self
.
aio_obj
=
server
.
Server
(
loop
=
_tloop
.
loop
)
_tloop
.
post
(
self
.
aio_obj
.
init
(
shelf_file
))
self
.
nodes
=
Shortcuts
(
self
.
aio_obj
.
iserver
.
isession
)
def
set_endpoint
(
self
,
url
):
return
self
.
aio_obj
.
set_endpoint
(
url
)
@
syncmethod
def
start
(
self
):
...
...
@@ -134,4 +151,24 @@ class Server(server.Server):
def
stop
(
self
):
pass
def
get_node
(
self
,
nodeid
):
return
Node
(
server
.
Server
.
get_node
(
self
,
nodeid
))
class
Node
:
def
__init__
(
self
,
aio_node
):
self
.
aio_obj
=
aio_node
global
_tloop
@
syncmethod
def
get_browse_name
(
self
):
pass
@
syncmethod
def
get_children
(
self
):
pass
def
__eq__
(
self
,
other
):
return
self
.
aio_obj
==
other
.
aio_obj
tests/test_sync.py
View file @
7a949baa
...
...
@@ -29,6 +29,15 @@ def client(tloop, server):
c
.
disconnect
()
def
test_sync
1
(
client
):
def
test_sync
_client
(
client
):
print
(
client
.
nodes
.
root
)
time
.
sleep
(
2
)
def
test_sync_get_node
(
client
):
node
=
client
.
get_node
(
85
)
assert
node
==
client
.
nodes
.
objects
nodes
=
node
.
get_children
()
assert
len
(
nodes
)
==
1
assert
nodes
[
0
]
==
client
.
nodes
.
server
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