| @@ 259-293 (lines=35) @@ | ||
| 256 | sys.exit(0) |
|
| 257 | print(args) |
|
| 258 | ||
| 259 | ||
| 260 | def uals(): |
|
| 261 | parser = argparse.ArgumentParser(description="Browse OPC-UA node and print result") |
|
| 262 | add_common_args(parser) |
|
| 263 | parser.add_argument("-l", |
|
| 264 | dest="long_format", |
|
| 265 | const=3, |
|
| 266 | nargs="?", |
|
| 267 | type=int, |
|
| 268 | help="use a long listing format") |
|
| 269 | parser.add_argument("-d", |
|
| 270 | "--depth", |
|
| 271 | default=1, |
|
| 272 | type=int, |
|
| 273 | help="Browse depth") |
|
| 274 | ||
| 275 | args = parse_args(parser) |
|
| 276 | if args.long_format is None: |
|
| 277 | args.long_format = 1 |
|
| 278 | ||
| 279 | client = Client(args.url, timeout=args.timeout) |
|
| 280 | client.set_security_string(args.security) |
|
| 281 | client.connect() |
|
| 282 | try: |
|
| 283 | node = get_node(client, args) |
|
| 284 | print("Browsing node {0} at {1}\n".format(node, args.url)) |
|
| 285 | if args.long_format == 0: |
|
| 286 | _lsprint_0(node, args.depth - 1) |
|
| 287 | elif args.long_format == 1: |
|
| 288 | _lsprint_1(node, args.depth - 1) |
|
| 289 | else: |
|
| 290 | _lsprint_long(node, args.depth - 1) |
|
| 291 | finally: |
|
| 292 | client.disconnect() |
|
| 293 | sys.exit(0) |
|
| 294 | print(args) |
|
| 295 | ||
| 296 | ||
| @@ 95-128 (lines=34) @@ | ||
| 92 | node = node.get_child(path) |
|
| 93 | return node |
|
| 94 | ||
| 95 | ||
| 96 | def uaread(): |
|
| 97 | parser = argparse.ArgumentParser(description="Read attribute of a node, per default reads value of a node") |
|
| 98 | add_common_args(parser) |
|
| 99 | parser.add_argument("-a", |
|
| 100 | "--attribute", |
|
| 101 | dest="attribute", |
|
| 102 | type=int, |
|
| 103 | default=ua.AttributeIds.Value, |
|
| 104 | help="Set attribute to read") |
|
| 105 | parser.add_argument("-t", |
|
| 106 | "--datatype", |
|
| 107 | dest="datatype", |
|
| 108 | default="python", |
|
| 109 | choices=['python', 'variant', 'datavalue'], |
|
| 110 | help="Data type to return") |
|
| 111 | ||
| 112 | args = parse_args(parser, requirenodeid=True) |
|
| 113 | ||
| 114 | client = Client(args.url, timeout=args.timeout) |
|
| 115 | client.set_security_string(args.security) |
|
| 116 | client.connect() |
|
| 117 | try: |
|
| 118 | node = get_node(client, args) |
|
| 119 | attr = node.get_attribute(args.attribute) |
|
| 120 | if args.datatype == "python": |
|
| 121 | print(attr.Value.Value) |
|
| 122 | elif args.datatype == "variant": |
|
| 123 | print(attr.Value) |
|
| 124 | else: |
|
| 125 | print(attr) |
|
| 126 | finally: |
|
| 127 | client.disconnect() |
|
| 128 | sys.exit(0) |
|
| 129 | print(args) |
|
| 130 | ||
| 131 | ||