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
7d99e8bd
Commit
7d99e8bd
authored
Jan 10, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small examples update
parent
cfe6d6e5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
52 deletions
+6
-52
examples/example-client-minimal.py
examples/example-client-minimal.py
+0
-37
examples/example-server-methods.py
examples/example-server-methods.py
+4
-13
examples/example-server.py
examples/example-server.py
+2
-2
No files found.
examples/example-client-minimal.py
deleted
100644 → 0
View file @
cfe6d6e5
import
sys
sys
.
path
.
insert
(
0
,
".."
)
from
opcua
import
Client
if
__name__
==
"__main__"
:
client
=
Client
(
"opc.tcp://localhost:4841/freeopcua/server/"
)
# client = Client("opc.tcp://admin@localhost:4841/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
)
# Node objects have methods to read and write node attributes as well as browse or populate address space
print
(
"Children of root are: "
,
root
.
get_children
())
# get a specific node knowing its node id
#var = client.get_node(ua.NodeId(1002, 2))
#var = client.get_node("ns=3;i=2002")
#print(var)
#var.get_data_value() # get value of node as a DataValue object
#var.get_value() # get value of node as a python builtin
#var.set_value(ua.Variant([23], ua.VariantType.Int64)) #set node value using explicit data type
#var.set_value(3.9) # set node value using implicit data type
# Now getting a variable node using its browse path
myvar
=
root
.
get_child
([
"0:Objects"
,
"2:MyObject"
,
"2:MyVariable"
])
obj
=
root
.
get_child
([
"0:Objects"
,
"2:MyObject"
])
print
(
"myvar is: "
,
myvar
)
finally
:
client
.
disconnect
()
examples/example-server-methods.py
View file @
7d99e8bd
...
@@ -14,7 +14,7 @@ except ImportError:
...
@@ -14,7 +14,7 @@ except ImportError:
shell
.
interact
()
shell
.
interact
()
from
opcua
import
ua
,
uamethod
,
Server
,
Event
,
ObjectIds
from
opcua
import
ua
,
uamethod
,
Server
,
Event
# method to be exposed through server
# method to be exposed through server
...
@@ -73,34 +73,25 @@ if __name__ == "__main__":
...
@@ -73,34 +73,25 @@ if __name__ == "__main__":
inargx
=
ua
.
Argument
()
inargx
=
ua
.
Argument
()
inargx
.
Name
=
"x"
inargx
.
Name
=
"x"
inargx
.
DataType
=
ua
.
NodeId
(
ObjectIds
.
Int64
)
inargx
.
DataType
=
ua
.
NodeId
(
ua
.
ObjectIds
.
Int64
)
inargx
.
ValueRank
=
-
1
inargx
.
ValueRank
=
-
1
inargx
.
ArrayDimensions
=
[]
inargx
.
ArrayDimensions
=
[]
inargx
.
Description
=
ua
.
LocalizedText
(
"First number x"
)
inargx
.
Description
=
ua
.
LocalizedText
(
"First number x"
)
inargy
=
ua
.
Argument
()
inargy
=
ua
.
Argument
()
inargy
.
Name
=
"y"
inargy
.
Name
=
"y"
inargy
.
DataType
=
ua
.
NodeId
(
ObjectIds
.
Int64
)
inargy
.
DataType
=
ua
.
NodeId
(
ua
.
ObjectIds
.
Int64
)
inargy
.
ValueRank
=
-
1
inargy
.
ValueRank
=
-
1
inargy
.
ArrayDimensions
=
[]
inargy
.
ArrayDimensions
=
[]
inargy
.
Description
=
ua
.
LocalizedText
(
"Second number y"
)
inargy
.
Description
=
ua
.
LocalizedText
(
"Second number y"
)
outarg
=
ua
.
Argument
()
outarg
=
ua
.
Argument
()
outarg
.
Name
=
"Result"
outarg
.
Name
=
"Result"
outarg
.
DataType
=
ua
.
NodeId
(
ObjectIds
.
Int64
)
outarg
.
DataType
=
ua
.
NodeId
(
ua
.
ObjectIds
.
Int64
)
outarg
.
ValueRank
=
-
1
outarg
.
ValueRank
=
-
1
outarg
.
ArrayDimensions
=
[]
outarg
.
ArrayDimensions
=
[]
outarg
.
Description
=
ua
.
LocalizedText
(
"Multiplication result"
)
outarg
.
Description
=
ua
.
LocalizedText
(
"Multiplication result"
)
multiply_node
=
myobj
.
add_method
(
idx
,
"multiply"
,
multiply
,
[
inargx
,
inargy
],
[
outarg
])
multiply_node
=
myobj
.
add_method
(
idx
,
"multiply"
,
multiply
,
[
inargx
,
inargy
],
[
outarg
])
# import some nodes from xml
server
.
import_xml
(
"custom_nodes.xml"
)
# creating an event object
# The event object automatically will have members for all events properties
myevent
=
server
.
get_event_object
(
ObjectIds
.
BaseEventType
)
myevent
.
Message
.
Text
=
"This is my event"
myevent
.
Severity
=
300
# starting!
# starting!
server
.
start
()
server
.
start
()
print
(
"Available loggers are: "
,
logging
.
Logger
.
manager
.
loggerDict
.
keys
())
print
(
"Available loggers are: "
,
logging
.
Logger
.
manager
.
loggerDict
.
keys
())
...
...
examples/example-server.py
View file @
7d99e8bd
...
@@ -14,7 +14,7 @@ except ImportError:
...
@@ -14,7 +14,7 @@ except ImportError:
shell
.
interact
()
shell
.
interact
()
from
opcua
import
ua
,
uamethod
,
Server
,
Event
,
ObjectIds
from
opcua
import
ua
,
uamethod
,
Server
,
Event
class
SubHandler
(
object
):
class
SubHandler
(
object
):
...
@@ -92,7 +92,7 @@ if __name__ == "__main__":
...
@@ -92,7 +92,7 @@ if __name__ == "__main__":
# creating an event object
# creating an event object
# The event object automatically will have members for all events properties
# The event object automatically will have members for all events properties
myevent
=
server
.
get_event_object
(
ObjectIds
.
BaseEventType
)
myevent
=
server
.
get_event_object
(
ua
.
ObjectIds
.
BaseEventType
)
myevent
.
Message
.
Text
=
"This is my event"
myevent
.
Message
.
Text
=
"This is my event"
myevent
.
Severity
=
300
myevent
.
Severity
=
300
...
...
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