YARP is another robot development platform, similar to ROS. I had to code up a simple data reader in Python (operating over YARP ports) and couldn’t find any good examples. After some experimenting, I found a solution that worked for me. The following is a simple code snippet for other YARP Python newbies:
class ExampleReader: def __init__(self): #create a new input port and open it self.in_port = yarp.BufferedPortBottle() self.in_port.open("/example/data:i") #connect up the output port to our input port yarp.Network.connect("/example/data:o", "/example/data:i") return def getData(self): #in this example, I assume the data is a single integer #we use read() where the parameter determines if it is #blocking (True) or not. btl = self.in_port.read(True) my_data = btl.get(0).asInt() #if you have doubles, you can use asDouble() #or strings can be obtained using asString() return my_data