Skip to content

Commit

Permalink
add uaread tool
Browse files Browse the repository at this point in the history
  • Loading branch information
oroulet committed Nov 18, 2015
1 parent c123f19 commit cee01ee
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 21 deletions.
87 changes: 87 additions & 0 deletions opcua/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import logging
import os
import sys
import argparse
from opcua import ua, Client


def add_common_args(parser, nodeid_required=True):
parser.add_argument("-u",
"--url",
help="URL of OPC UA server (for example: opc.tcp://example.org:4840)",
default='opc.tcp://localhost:4841',
metavar="URL")
parser.add_argument("-n",
"--nodeid",
help="Fully-qualified node ID (for example: i=85). Default: root node",
default='i=84',
required=nodeid_required,
#required=True,
metavar="NODE")
parser.add_argument("-p",
"--path",
help="Comma separated browse path to the node starting at nodeid (for example: 3:Mybject,3:MyVariable)",
default='',
metavar="BROWSEPATH")
parser.add_argument("-i",
"--namespace",
help="Default namespace",
type=int,
default=0,
metavar="NAMESPACE")

parser.add_argument("-v",
"--verbose",
dest="loglevel",
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
default='WARNING',
help="Set log level")


def get_node(client, args):
node = client.get_node(args.nodeid)
if args.path:
node = node.get_child(args.path.split(","))


def uaread():
parser = argparse.ArgumentParser(description="Read attribute of a node")
add_common_args(parser)
parser.add_argument("-a",
"--attribute",
dest="attribute",
type=int,
#default="VALUE",
#choices=['VALUE', 'NODEID', 'BROWSENAME', 'ERROR', 'CRITICAL'],
default=ua.AttributeIds.Value,
help="Set attribute to read")
parser.add_argument("-t",
"--datatype",
dest="datatype",
default="python",
choices=['python', 'variant', 'datavalue'],
help="Data type to return")

args = parser.parse_args()
logging.basicConfig(format="%(levelname)s: %(message)s", level=getattr(logging, args.loglevel))

client = Client(args.url)
client.connect()
try:
node = client.get_node(args.nodeid)
if args.path:
node = node.get_child(args.path.split(","))
attr = node.get_attribute(args.attribute)
if args.datatype == "python":
print(attr.Value.Value)
elif args.datatype == "variant":
print(attr.Value)
else:
print(attr)
finally:
client.disconnect()
sys.exit(0)
print(args)



44 changes: 23 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@
else:
install_requires = []

setup(
name = "freeopcua",
version = "0.9.12",
description = "Pure Python OPC-UA client and server library",
author = "Olivier Roulet-Dubonnet",
author_email = "olivier.roulet@gmail.com",
url = 'http://freeopcua.github.io/',
packages = ["opcua"],
provides = ["opcua"],
license = "GNU Lesser General Public License",
install_requires = install_requires,
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
]
)
setup(name="freeopcua",
version="0.9.12",
description="Pure Python OPC-UA client and server library",
author="Olivier Roulet-Dubonnet",
author_email="olivier.roulet@gmail.com",
url='http://freeopcua.github.io/',
packages=["opcua"],
provides=["opcua"],
license="GNU Lesser General Public License",
install_requires=install_requires,
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
]
entry_points={'console_scripts':
['uaread = opcua.uaread']
}
)


11 changes: 11 additions & 0 deletions tools/uaread
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python

import sys
import os
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

from opcua.tools import uaread


if __name__ == "__main__":
uaread()

0 comments on commit cee01ee

Please sign in to comment.