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