mirror of
				https://github.com/FreeOpcUa/opcua-asyncio
				synced 2025-10-29 17:07:18 +08:00 
			
		
		
		
	clean up uacall
This commit is contained in:
		| @@ -711,15 +711,15 @@ async def _uacall(): | |||||||
|     parser.add_argument("-m", |     parser.add_argument("-m", | ||||||
|                         "--method", |                         "--method", | ||||||
|                         dest="method", |                         dest="method", | ||||||
|                         type=int, |  | ||||||
|                         default=None, |  | ||||||
|                         help="Set method to call. If not given then (single) method of the selected node is used.") |  | ||||||
|     parser.add_argument("-M", |  | ||||||
|                         "--method-name", |  | ||||||
|                         dest="method_name", |  | ||||||
|                         type=str, |                         type=str, | ||||||
|                         default=None, |                         default=None, | ||||||
|                         help="Set name of method to call. Overrides --method") |                         help="browse name of method to call") | ||||||
|  |     parser.add_argument("-t", | ||||||
|  |                         "--datatype", | ||||||
|  |                         dest="datatype", | ||||||
|  |                         default="guess", | ||||||
|  |                         choices=["guess", 'byte', 'sbyte', 'nodeid', 'expandednodeid', 'qualifiedname', 'browsename', 'string', 'float', 'double', 'int16', 'int32', "int64", 'uint16', 'uint32', 'uint64', "bool", "string", 'datetime', 'bytestring', 'xmlelement', 'statuscode', 'localizedtext'], | ||||||
|  |                         help="Data type to return") | ||||||
|     parser.add_argument("-l", |     parser.add_argument("-l", | ||||||
|                         "--list", |                         "--list", | ||||||
|                         "--array", |                         "--array", | ||||||
| @@ -727,14 +727,8 @@ async def _uacall(): | |||||||
|                         default="guess", |                         default="guess", | ||||||
|                         choices=["guess", "true", "false"], |                         choices=["guess", "true", "false"], | ||||||
|                         help="Value is an array") |                         help="Value is an array") | ||||||
|     parser.add_argument("-t", |  | ||||||
|                         "--datatype", |  | ||||||
|                         dest="datatype", |  | ||||||
|                         default="guess", |  | ||||||
|                         choices=["guess", 'byte', 'sbyte', 'nodeid', 'expandednodeid', 'qualifiedname', 'browsename', 'string', 'float', 'double', 'int16', 'int32', "int64", 'uint16', 'uint32', 'uint64', "bool", "string", 'datetime', 'bytestring', 'xmlelement', 'statuscode', 'localizedtext'], |  | ||||||
|                         help="Data type to return") |  | ||||||
|     parser.add_argument("value", |     parser.add_argument("value", | ||||||
|                         help="Value to use for call to method, if any", |                         help="Comma separated value(s) to use for call to method, if any", | ||||||
|                         nargs="?", |                         nargs="?", | ||||||
|                         metavar="VALUE") |                         metavar="VALUE") | ||||||
|  |  | ||||||
| @@ -745,40 +739,24 @@ async def _uacall(): | |||||||
|     await client.connect() |     await client.connect() | ||||||
|     try: |     try: | ||||||
|         node = await get_node(client, args) |         node = await get_node(client, args) | ||||||
|         # val must be a tuple in order to enable method calls without arguments |         if args.value is None: | ||||||
|         if ( args.value is None ): |             val = ()  # empty tuple | ||||||
|             val = () #empty tuple |  | ||||||
|         else: |         else: | ||||||
|             val = (_val_to_variant(args.value, args),) # tuple with one element |             val = args.value.split(",") | ||||||
|  |             val = [_val_to_variant(v, args) for v in val] | ||||||
|  |  | ||||||
|         # determine method to call: Either explicitly given or automatically select the method of the selected node. |  | ||||||
|         methods = await node.get_methods() |  | ||||||
|         method_id = None |         method_id = None | ||||||
|         #print( "methods=%s" % (methods) ) |  | ||||||
|  |  | ||||||
|         if ( args.method_name is not None ): |         if args.method is not None: | ||||||
|             method_id = args.method_name |             method_id = args.method | ||||||
|         elif ( args.method is None ): |  | ||||||
|             if ( len( methods ) == 0 ): |  | ||||||
|                 raise ValueError( "No methods in selected node and no method given" ) |  | ||||||
|             elif ( len( methods ) == 1 ): |  | ||||||
|                 method_id = methods[0] |  | ||||||
|             else: |  | ||||||
|                 raise ValueError( "Selected node has {0:d} methods but no method given. Provide one of {1!s}".format(*(methods)) ) |  | ||||||
|         else: |         else: | ||||||
|             for m in methods: |             methods = await node.get_methods() | ||||||
|                 if ( m.nodeid.Identifier == args.method ): |             if len(methods) == 0: | ||||||
|                     method_id = m.nodeid |                 raise ValueError("No methods in selected node and no method given") | ||||||
|                     break |             else: | ||||||
|  |                 method_id = methods[0] | ||||||
|         if ( method_id is None): |         result = await node.call_method(method_id, *val) | ||||||
|             # last resort: |         print(f"resulting result_variants={result}") | ||||||
|             method_id = ua.NodeId( identifier=args.method )#, namespaceidx=? )#, nodeidtype=?): ) |  | ||||||
|  |  | ||||||
|         #print( "method_id=%s\nval=%s" % (method_id,val) ) |  | ||||||
|  |  | ||||||
|         result_variants = await node.call_method( method_id, *val ) |  | ||||||
|         print( "resulting result_variants={0!s}".format(result_variants) ) |  | ||||||
|     finally: |     finally: | ||||||
|         await client.disconnect() |         await client.disconnect() | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								tools/uacall
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										2
									
								
								tools/uacall
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
|  |  | ||||||
| import sys | import sys | ||||||
| import os | import os | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
|  |  | ||||||
| import sys | import sys | ||||||
| import os | import os | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 oroulet
					oroulet