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
369c4f5d
Commit
369c4f5d
authored
May 03, 2016
by
Denis Štogl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Example update and new client-events example
parent
75b1bf9a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
8 deletions
+77
-8
examples/client-events.py
examples/client-events.py
+57
-0
examples/server-events.py
examples/server-events.py
+16
-5
examples/server-example.py
examples/server-example.py
+4
-3
No files found.
examples/client-events.py
0 → 100644
View file @
369c4f5d
import
sys
sys
.
path
.
insert
(
0
,
".."
)
try
:
from
IPython
import
embed
except
ImportError
:
import
code
def
embed
():
vars
=
globals
()
vars
.
update
(
locals
())
shell
=
code
.
InteractiveConsole
(
vars
)
shell
.
interact
()
from
opcua
import
Client
class
SubHandler
(
object
):
"""
Subscription Handler. To receive events from server for a subscription
data_change and event methods are called directly from receiving thread.
Do not do expensive, slow or network operation there. Create another
thread if you need to do such a thing
"""
def
event_notification
(
self
,
event
):
print
(
"New event recived: "
,
event
)
if
__name__
==
"__main__"
:
client
=
Client
(
"opc.tcp://localhost:4840/freeopcua/server/"
)
# client = Client("opc.tcp://admin@localhost:4840/freeopcua/server/") #connect using a user
try
:
client
.
connect
()
# Client has a few methods to get proxy to UA nodes that should always be in address space such as Root or Objects
root
=
client
.
get_root_node
()
print
(
"Objects node is: "
,
root
)
# Now getting a variable node using its browse path
obj
=
root
.
get_child
([
"0:Objects"
,
"2:MyObject"
])
print
(
"MyObject is: "
,
obj
)
myevent
=
root
.
get_child
([
"0:Types"
,
"0:EventTypes"
,
"0:BaseEventType"
,
"2:MyFirstEvent"
])
print
(
"MyFirstEventType is: "
,
myevent
)
msclt
=
SubHandler
()
sub
=
client
.
create_subscription
(
100
,
msclt
)
handle
=
sub
.
subscribe_events
(
obj
,
myevent
)
embed
()
sub
.
unsubscribe
(
handle
)
sub
.
delete
()
finally
:
client
.
disconnect
()
examples/server-events.py
View file @
369c4f5d
import
sys
import
logging
try
:
from
IPython
import
embed
except
ImportError
:
import
code
def
embed
():
vars
=
globals
()
vars
.
update
(
locals
())
shell
=
code
.
InteractiveConsole
(
vars
)
shell
.
interact
()
from
opcua
import
ua
,
Server
...
...
@@ -42,12 +53,12 @@ if __name__ == "__main__":
try
:
# time.sleep is here just because we want to see events in UaExpert
import
time
time
.
sleep
(
10
)
myevgen
.
trigger
(
message
=
"This is MyFirstEvent with MyNumericProperty and MyStringProperty."
)
mysecondevgen
.
trigger
(
message
=
"This is MySecondEvent with MyIntProperty and MyBoolProperty."
)
for
i
in
range
(
1
,
10
):
time
.
sleep
(
10
)
myevgen
.
trigger
(
message
=
"This is MyFirstEvent with MyNumericProperty and MyStringProperty."
)
mysecondevgen
.
trigger
(
message
=
"This is MySecondEvent with MyIntProperty and MyBoolProperty."
)
time
.
sleep
(
20
)
embed
(
)
finally
:
#close connection, remove subcsriptions, etc
server
.
stop
()
examples/server-example.py
View file @
369c4f5d
...
...
@@ -14,7 +14,7 @@ except ImportError:
shell
.
interact
()
from
opcua
import
ua
,
uamethod
,
Server
,
EventGenerator
from
opcua
import
ua
,
uamethod
,
Server
class
SubHandler
(
object
):
...
...
@@ -92,7 +92,8 @@ if __name__ == "__main__":
# creating an event object
# The event object automatically will have members for all events properties
myevgen
=
server
.
get_event_generator
(
ua
.
BaseEvent
(
message
=
"This is BaseEvent"
,
severity
=
300
))
myevgen
=
server
.
get_event_generator
()
myevgen
.
event
.
Severity
=
300
# starting!
server
.
start
()
...
...
@@ -103,7 +104,7 @@ if __name__ == "__main__":
#sub = server.create_subscription(500, handler)
#handle = sub.subscribe_data_change(myvar)
# trigger event, all subscribed clients wil receive it
myevgen
.
trigger
()
myevgen
.
trigger
(
message
=
"This is BaseEvent"
)
embed
()
finally
:
...
...
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