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
21ffd6af
Commit
21ffd6af
authored
Nov 08, 2022
by
oroulet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up some examples
parent
5388d501
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
19 deletions
+25
-19
examples/client-example.py
examples/client-example.py
+3
-1
examples/client-reconnect.py
examples/client-reconnect.py
+1
-1
examples/server-example.py
examples/server-example.py
+20
-16
examples/server-minimal.py
examples/server-minimal.py
+1
-1
No files found.
examples/client-example.py
View file @
21ffd6af
...
...
@@ -3,7 +3,7 @@ import logging
from
asyncua
import
Client
_logger
=
logging
.
getLogger
(
'asyncua'
)
_logger
=
logging
.
getLogger
(
__name__
)
class
SubHandler
(
object
):
...
...
@@ -13,6 +13,7 @@ class SubHandler(object):
Do not do expensive, slow or network operation there. Create another
thread if you need to do such a thing
"""
def
datachange_notification
(
self
,
node
,
val
,
data
):
print
(
"New data change event"
,
node
,
val
)
...
...
@@ -32,6 +33,7 @@ async def main():
uri
=
"http://examples.freeopcua.github.io"
idx
=
await
client
.
get_namespace_index
(
uri
)
_logger
.
info
(
"index of our namespace is %s"
,
idx
)
# get a specific node knowing its node id
#var = client.get_node(ua.NodeId(1002, 2))
#var = client.get_node("ns=3;i=2002")
...
...
examples/client-reconnect.py
View file @
21ffd6af
...
...
@@ -4,7 +4,7 @@ import asyncio
from
asyncua
import
Client
,
ua
,
Node
_logger
=
logging
.
getLogger
(
"asyncua"
)
_logger
=
logging
.
getLogger
(
__name__
)
class
SubHandler
:
...
...
examples/server-example.py
View file @
21ffd6af
...
...
@@ -9,6 +9,9 @@ from math import sin
from
asyncua
import
ua
,
uamethod
,
Server
_logger
=
logging
.
getLogger
(
__name__
)
class
SubHandler
(
object
):
"""
...
...
@@ -16,10 +19,10 @@ class SubHandler(object):
"""
def
datachange_notification
(
self
,
node
,
val
,
data
):
print
(
"Python: New data change event
"
,
node
,
val
)
_logger
.
warn
(
"Python: New data change event %s %s
"
,
node
,
val
)
def
event_notification
(
self
,
event
):
print
(
"Python: New event
"
,
event
)
_logger
.
warn
(
"Python: New event %s
"
,
event
)
# method to be exposed through server
...
...
@@ -34,22 +37,12 @@ def func(parent, variant):
# uses a decorator to automatically convert to and from variants
@
uamethod
def
multiply
(
parent
,
x
,
y
):
print
(
"multiply method call with parameters:
"
,
x
,
y
)
_logger
.
warn
(
"multiply method call with parameters: %s %s
"
,
x
,
y
)
return
x
*
y
async
def
main
():
# optional: setup logging
# logger = logging.getLogger("asyncua.address_space")
# logger.setLevel(logging.DEBUG)
# logger = logging.getLogger("asyncua.internal_server")
# logger.setLevel(logging.DEBUG)
# logger = logging.getLogger("asyncua.binary_server_asyncio")
# logger.setLevel(logging.DEBUG)
# logger = logging.getLogger("asyncua.uaprocessor")
# logger.setLevel(logging.DEBUG)
# now setup our server
server
=
Server
()
await
server
.
init
()
# server.disable_clock() #for debuging
...
...
@@ -135,9 +128,10 @@ async def main():
await
myarrayvar
.
write_value
(
var
)
await
mydevice_var
.
write_value
(
"Running"
)
await
myevgen
.
trigger
(
message
=
"This is BaseEvent"
)
await
server
.
write_attribute_value
(
myvar
.
nodeid
,
ua
.
DataValue
(
0.9
)
)
# Server side write method which is a bit faster than using write_value
# write_attribute_value is a server side method which is faster than using write_value
# but than methods has less checks
await
server
.
write_attribute_value
(
myvar
.
nodeid
,
ua
.
DataValue
(
0.9
))
while
True
:
await
asyncio
.
sleep
(
0.1
)
await
server
.
write_attribute_value
(
myvar
.
nodeid
,
ua
.
DataValue
(
sin
(
time
.
time
())))
...
...
@@ -145,4 +139,14 @@ async def main():
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
# optional: setup logging
# logger = logging.getLogger("asyncua.address_space")
# logger.setLevel(logging.DEBUG)
# logger = logging.getLogger("asyncua.internal_server")
# logger.setLevel(logging.DEBUG)
# logger = logging.getLogger("asyncua.binary_server_asyncio")
# logger.setLevel(logging.DEBUG)
# logger = logging.getLogger("asyncua.uaprocessor")
# logger.setLevel(logging.DEBUG)
asyncio
.
run
(
main
())
examples/server-minimal.py
View file @
21ffd6af
...
...
@@ -11,7 +11,7 @@ def func(parent, value):
async
def
main
():
_logger
=
logging
.
getLogger
(
"asyncua"
)
_logger
=
logging
.
getLogger
(
__name__
)
# setup our server
server
=
Server
()
await
server
.
init
()
...
...
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