#!/usr/bin/env python import sys from omniORB import CORBA from RTT import Corba import CosNaming import time # Initialise the ORB orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) # If IOR is given as command line parameter if len(sys.argv) == 2: ior = sys.argv[1] obj = orb.string_to_object(ior) elif len(sys.argv) == 1: # if no IOR, use omniNames instead # Obtain a reference to the root naming context obj = orb.resolve_initial_references("NameService") rootContext = obj._narrow(CosNaming.NamingContext) if rootContext is None: print "Failed to narrow the root naming context" sys.exit(1) # Resolve the name "ControlTasks/your_component_name" # see SmallNetwork.cpp and ExecutionServer.hpp name = [CosNaming.NameComponent("ControlTasks",""),CosNaming.NameComponent("ComponentA","")] try: obj = rootContext.resolve(name) except CosNaming.NamingContext.NotFound, ex: print "Name not found" sys.exit(1) # Narrow the object to a Corba::ControlObject # See ControlTask.idl eo = obj._narrow(Corba.ControlObject) if eo is None: print "Object reference is not an Corba::ControlObject" sys.exit(1) # get properties and attributes. See ControlTask.idl ep= eo.attributes() # get a specific property. See Attributes.idl props = ep.getProperty("Strength") # a corba value corbval = CORBA.Any(CORBA.TC_long, 9) # change the property value props.set(corbval) props.evaluate() print("the new value of Strength is %s " % props.toString()) # this is how commands are created. arg1 = corbval arg2 = CORBA.Any(CORBA.TC_long, 10) arg3 = CORBA.Any(CORBA.TC_long, 11) cmdi = eo.commands() # see OperationInterface.idl cmd = cmdi.createCommandAny("command",[arg1,arg2,arg3]) # and this is how they are executed with the original arguments (Operations.idl) cmd.execute() # optionally, check if the command is done time.sleep(1) cmd.done() # # call the command with new arguments cmd.reset() cmd.executeAny([arg3, arg2, arg1]) time.sleep(1) cmd.done()