Commit cec7a8e6 authored by olivier R-D's avatar olivier R-D

add uaclient command line

parent fac754b9
......@@ -2,7 +2,6 @@ import logging
import sys
import argparse
from datetime import datetime
import code
from enum import Enum
try:
......@@ -11,10 +10,7 @@ except ImportError:
import code
def embed():
vars = globals()
vars.update(locals())
shell = code.InteractiveConsole(vars)
shell.interact()
code.interact(local=dict(globals(), **locals()))
from opcua import ua
from opcua import Client
......@@ -51,7 +47,7 @@ def add_common_args(parser):
metavar="NODE")
parser.add_argument("-p",
"--path",
help="Comma separated browse path to the node starting at nodeid (for example: 3:Mybject,3:MyVariable)",
help="Comma separated browse path to the node starting at NODE (for example: 3:Mybject,3:MyVariable)",
default='',
metavar="BROWSEPATH")
parser.add_argument("-i",
......@@ -372,10 +368,7 @@ def uasubscribe():
sub.subscribe_data_change(node)
else:
sub.subscribe_events(node)
glbs = globals()
glbs.update(locals())
shell = code.InteractiveConsole(vars)
shell.interact()
embed()
finally:
client.disconnect()
sys.exit(0)
......@@ -435,6 +428,38 @@ def endpoint_to_strings(ep):
return result
def uaclient():
parser = argparse.ArgumentParser(description="Connect to server and start python shell. root and objects nodes are available. Node specificed in command line is available as mynode variable")
add_common_args(parser)
parser.add_argument("-c",
"--certificate",
help="set client certificate")
parser.add_argument("-k",
"--private_key",
help="set client private key")
args = parser.parse_args()
logging.basicConfig(format="%(levelname)s: %(message)s", level=getattr(logging, args.loglevel))
client = Client(args.url, timeout=args.timeout)
client.connect()
if args.certificate:
client.load_certificate(args.certificate)
if args.private_key:
client.load_certificate(args.private_key)
try:
root = client.get_root_node()
objects = client.get_objects_node()
mynode = client.get_node(args.nodeid)
if args.path:
mynode = mynode.get_child(args.path.split(","))
embed()
finally:
client.disconnect()
sys.exit(0)
def uaserver():
parser = argparse.ArgumentParser(description="Run an example OPC-UA server. By importing xml definition and using uawrite, it is even possible to expose real data using this server")
add_minimum_args(parser)
......
......@@ -34,6 +34,8 @@ setup(name="freeopcua",
'uawrite = opcua.tools:uawrite',
'uasubscribe = opcua.tools:uasubscribe',
'uahistoryread = opcua.tools:uahistoryread',
'uaclient = opcua.tools:uaclient',
'uaserver = opcua.tools:uaserver',
'uadiscover = opcua.tools:uadiscover'
]
}
......
#!/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 uaclient
if __name__ == "__main__":
uaclient()
#!/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 uaserver
if __name__ == "__main__":
uaserver()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment