def to_tc_value(data, type_): if data == None: return any.to_any(None) tc, data = any._to_tc_value(data) # first getting the appropriate TypeCode based on the type_ attribute if __TYPE_MAP.has_key(type_): pytype = __TYPE_MAP[type_][0] tc = __TYPE_MAP[type_][1] if type(data) != pytype: data = to_pyvalue(data, type_) return CORBA.Any(tc, data)
def readDataPort(port, timeout=1.0): pprof = port.get_port_profile() for prop in pprof.properties: if prop.name == "dataport.data_type": classname = any.from_any(prop.value) if prop.name == "dataport.data_value": return any._to_tc_value(prop.value)[1] nv1 = SDOPackage.NameValue("dataport.interface_type", any.to_any("corba_cdr")) nv2 = SDOPackage.NameValue("dataport.dataflow_type", any.to_any("Pull")) nv3 = SDOPackage.NameValue("dataport.subscription_type", any.to_any("flush")) con_prof = RTC.ConnectorProfile("connector0", "", [port], [nv1, nv2, nv3]) ret, prof = port.connect(con_prof) if ret != RTC.RTC_OK: print("failed to connect") return None for p in prof.properties: # print(p.name) if p.name == 'dataport.corba_cdr.outport_ior': ior = any.from_any(p.value) obj = orb.string_to_object(ior) outport = obj._narrow(OutPortCdr) tm = 0 while tm < timeout: try: ret, data = outport.get() if ret == OpenRTM.PORT_OK: port.disconnect(prof.connector_id) tokens = classname.split(':') if len(tokens) == 3: # for 1.1? classname = tokens[1].replace('/', '.') return cdr2data(data, classname) except: pass time.sleep(0.1) tm = tm + 0.1 port.disconnect(prof.connector_id) return None