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
a0101228
Commit
a0101228
authored
Apr 28, 2019
by
Christian Bergmiller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
documentation
parent
4591658b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
7 deletions
+20
-7
examples/client-subscription.py
examples/client-subscription.py
+20
-7
No files found.
examples/client-subscription.py
View file @
a0101228
...
...
@@ -13,28 +13,41 @@ _logger = logging.getLogger('asyncua')
class
SubscriptionHandler
:
"""
The SubscriptionHandler is used to handle the data that is received for the subscription.
"""
def
datachange_notification
(
self
,
node
:
Node
,
val
,
data
):
"""Callback for asyncua Subscription"""
"""
Callback for asyncua Subscription.
This method will be called when the Client received a data change message from the Server.
"""
_logger
.
info
(
'datachange_notification %r %s'
,
node
,
val
)
async
def
main
():
url
=
'opc.tcp://localhost:4840/freeopcua/server/'
client
=
Client
(
url
=
url
)
# client.set_security_string()
"""
Main task of this Client-Subscription example.
"""
client
=
Client
(
url
=
'opc.tcp://localhost:4840/freeopcua/server/'
)
async
with
client
:
uri
=
'http://examples.freeopcua.github.io'
idx
=
await
client
.
get_namespace_index
(
uri
)
idx
=
await
client
.
get_namespace_index
(
uri
=
"http://examples.freeopcua.github.io"
)
var
=
await
client
.
nodes
.
objects
.
get_child
([
f"
{
idx
}
:MyObject"
,
f"
{
idx
}
:MyVariable"
])
handler
=
SubscriptionHandler
()
# We create a Client Subscription.
subscription
=
await
client
.
create_subscription
(
500
,
handler
)
nodes
=
[
var
,
client
.
get_node
(
ua
.
ObjectIds
.
Server_ServerStatus_CurrentTime
),
]
# We subscribe to data changes for two nodes (variables).
await
subscription
.
subscribe_data_change
(
nodes
)
# We let the subscription run for ten seconds
await
asyncio
.
sleep
(
10
)
# We delete the subscription (this un-subscribes from the data changes of the two variables).
# This is optional since closing the connection will also delete all subscriptions.
await
subscription
.
delete
()
# After one second we exit the Client context manager - this will close the connection.
await
asyncio
.
sleep
(
1
)
if
__name__
==
"__main__"
:
...
...
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