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
64cb7a02
Commit
64cb7a02
authored
Jun 27, 2020
by
Andreas Heine
Committed by
oroulet
Jun 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update client_to_kepware.py
parent
8c0fe344
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
35 deletions
+24
-35
examples/client_to_kepware.py
examples/client_to_kepware.py
+24
-35
No files found.
examples/client_to_kepware.py
View file @
64cb7a02
import
sys
import
asyncio
sys
.
path
.
insert
(
0
,
".."
)
import
logging
from
asyncua
import
Client
from
asyncua
import
Client
,
ua
class
SubHandler
(
object
):
"""
Client to subscription. It will receive events from server
Subscription Handler. To receive events from server for a subscription
"""
def
datachange_notification
(
self
,
node
,
val
,
data
):
...
...
@@ -18,38 +19,26 @@ class SubHandler(object):
print
(
"Python: New event"
,
event
)
if
__name__
==
"__main__"
:
#from IPython import embed
logging
.
basicConfig
(
level
=
logging
.
WARN
)
client
=
Client
(
"opc.tcp://192.168.56.100:49320/OPCUA/SimulationServer/"
)
#client = Client("opc.tcp://192.168.56.100:4840/OPCUA/SimulationServer/")
#client = Client("opc.tcp://olivier:olivierpass@localhost:53530/OPCUA/SimulationServer/")
try
:
client
.
connect
()
root
=
client
.
nodes
.
root
print
(
"Root is"
,
root
)
print
(
"childs of root are: "
,
root
.
get_children
())
print
(
"name of root is"
,
root
.
read_browse_name
())
objects
=
client
.
nodes
.
objects
print
(
"childs og objects are: "
,
objects
.
get_children
())
tag1
=
client
.
get_node
(
"ns=2;s=Channel1.Device1.Tag1"
)
print
(
f"tag1 is:
{
tag1
}
with value
{
tag1
.
read_value
()
}
"
)
tag2
=
client
.
get_node
(
"ns=2;s=Channel1.Device1.Tag2"
)
print
(
f"tag2 is:
{
tag2
}
with value
{
tag2
.
read_value
()
}
"
)
async
def
main
():
url
=
"opc.tcp://localhost:53530/OPCUA/SimulationServer/"
# url = "opc.tcp://olivier:olivierpass@localhost:53530/OPCUA/SimulationServer/"
async
with
Client
(
url
=
url
)
as
client
:
print
(
"Root children are"
,
await
client
.
nodes
.
root
.
get_children
())
tag1
=
await
client
.
get_node
(
"ns=2;s=Channel1.Device1.Tag1"
)
print
(
f"tag1 is:
{
tag1
}
with value
{
await
tag1
.
read_value
()
}
"
)
tag2
=
await
client
.
get_node
(
"ns=2;s=Channel1.Device1.Tag2"
)
print
(
f"tag2 is:
{
tag2
}
with value
{
await
tag2
.
read_value
()
}
"
)
handler
=
SubHandler
()
sub
=
client
.
create_subscription
(
500
,
handler
)
handle1
=
sub
.
subscribe_data_change
(
tag1
)
handle2
=
sub
.
subscribe_data_change
(
tag2
)
from
IPython
import
embed
embed
()
sub
.
unsubscribe
(
handle1
)
sub
.
unsubscribe
(
handle2
)
sub
.
delete
()
finally
:
client
.
disconnect
()
sub
=
await
client
.
create_subscription
(
500
,
handler
)
handle1
=
await
sub
.
subscribe_data_change
(
tag1
)
handle2
=
await
sub
.
subscribe_data_change
(
tag2
)
# await sub.unsubscribe(handle1)
# await sub.unsubscribe(handle2)
# await sub.delete()
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
WARN
)
asyncio
.
run
(
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