from parlay.utils import setup, discover, get_item_by_name setup() discover() e = get_item_by_name("Adder") e.x = 10 e.y = 12 handle = e.send_parlay_command("add", x=1, y=2) handle.wait_for_ack() print "ack1" handle.wait_for_ack() print "ack2" st = e.get_datastream_handle("st") print st.get() e.send_parlay_command("poll_stream") while st.get() < 100: print st.wait_for_value()
from parlay.utils import setup, discover, get_item_by_name setup() print "Discovering..." discover(force=True) print "Discovery Complete!" cheerful_person = get_item_by_name("CheerfulPerson") response = cheerful_person.say_hello() print response
""" Display the distance on the LCD """ from parlay.utils import setup, sleep, get_item_by_name, discover setup(ip="172.16.42.104") discover(force=False) LCD = get_item_by_name("LCD") # you can wait for complete on a handle if you want handle = LCD.send_parlay_command("init") handle.wait_for_complete() dist = get_item_by_name("DISTANCE_SENSOR") dist.init() #get a handle but DONT wait on it to finish since this loops forever handle = LCD.send_parlay_command("loop") handle = dist.send_parlay_command("poll_forever") print("STARTING...") for i in range(60): str_distance = "%.3f" % dist.DISTANCE print(str_distance) LCD.TEXT = str_distance sleep(1)
from parlay.utils import setup, discover, get_item_by_name setup() print("Discovering...") discover(force=True) print("Discovery Complete!") cheerful_person = get_item_by_name("CheerfulPerson") response = cheerful_person.say_hello() print(response)
from parlay.utils import discover, get_item_by_name, setup, sleep setup(ip="172.16.42.104") # This sets up the scripting environment and tells the script which IP to connect to. # default is localhost discover() # Issue a discovery (This must be done before get_item_by_name or get_item_by_id # we won't know what we're connected to!) rg_led = get_item_by_name("RG_LED") # Get an item by its name. If its ambiguous, it will return the first one # use get_item_by_id for unambiguous rg_led.init() # issue commands by calling them like functions (They can take arguments too) # commands called this way will BLOCK until they have been completed # if an error is returned, it will be raised as a BadStatusException() for i in range(20): rg_led.turn_green() sleep(1) rg_led.turn_red() sleep(1)
""" Blink the light, but display the color on the LCD """ from parlay.utils import discover, get_item_by_name, sleep, setup setup(ip="172.16.42.104") discover(force=False) led = get_item_by_name("RG_LED") led.init() LCD = get_item_by_name("LCD") handle = LCD.send_parlay_command("init") handle.wait_for_complete() #get a handle but DONT wait on it to finish since this loops forever handle = LCD.send_parlay_command("loop") print "STARTING..." for i in range(30): LCD.TEXT = "GREEN" print LCD.TEXT led.turn_green() sleep(1) LCD.TEXT = "RED" print LCD.TEXT led.turn_red() sleep(1)
from parlay.utils import discover, get_item_by_name, setup, sleep setup( ip="172.16.42.104" ) # This sets up the scripting environment and tells the script which IP to connect to. # default is localhost discover( ) # Issue a discovery (This must be done before get_item_by_name or get_item_by_id # we won't know what we're connected to!) rg_led = get_item_by_name( "RG_LED" ) # Get an item by its name. If its ambiguous, it will return the first one # use get_item_by_id for unambiguous rg_led.init( ) # issue commands by calling them like functions (They can take arguments too) # commands called this way will BLOCK until they have been completed # if an error is returned, it will be raised as a BadStatusException() for i in range(20): rg_led.turn_green() sleep(1) rg_led.turn_red() sleep(1)
from parlay.utils import setup, discover, get_item_by_name setup() discover() e = get_item_by_name("Adder") e.x = 10 e.y = 12 handle = e.send_parlay_command("add", x=1, y=2) handle.wait_for_ack() print("ack1") handle.wait_for_ack() print("ack2") st = e.get_datastream_handle("st") print(st.get()) e.send_parlay_command("poll_stream") while st.get() < 100: print(st.wait_for_value())
""" Blink the light, but display the color on the LCD """ from parlay.utils import discover, get_item_by_name, sleep, setup setup(ip="172.16.42.104") discover(force=False) led = get_item_by_name("RG_LED") led.init() LCD = get_item_by_name("LCD") handle = LCD.send_parlay_command("init") handle.wait_for_complete() #get a handle but DONT wait on it to finish since this loops forever handle = LCD.send_parlay_command("loop") print("STARTING...") for i in range(30): LCD.TEXT = "GREEN" print(LCD.TEXT) led.turn_green() sleep(1) LCD.TEXT = "RED" print(LCD.TEXT) led.turn_red() sleep(1)
from parlay.utils import setup, discover, get_item_by_name setup() discover() item1 = get_item_by_name("Item1") item2 = get_item_by_name("Item2") print "\nSending blocking commands" print " Slow Command 1..." response1 = item1.slow_command_1() print response1 print " Slow Command 2..." response2 = item2.slow_command_2() print response2 print "\nSending parallel commands" print " Slow Command 1..." cmd1 = item1.send_parlay_command("slow_command_1") print " Slow Command 2..." cmd2 = item2.send_parlay_command("slow_command_2") print " Waiting for responses..." response1 = cmd1.wait_for_complete()["CONTENTS"]["RESULT"] response2 = cmd2.wait_for_complete()["CONTENTS"]["RESULT"] print response1 print response2
""" Display the distance on the LCD """ from parlay.utils import setup, sleep, get_item_by_name, discover setup(ip="172.16.42.104") discover(force=False) LCD = get_item_by_name("LCD") # you can wait for complete on a handle if you want handle = LCD.send_parlay_command("init") handle.wait_for_complete() dist = get_item_by_name("DISTANCE_SENSOR") dist.init() #get a handle but DONT wait on it to finish since this loops forever handle = LCD.send_parlay_command("loop") handle = dist.send_parlay_command("poll_forever") print "STARTING..." for i in range(60): str_distance = "%.3f" % dist.DISTANCE print str_distance LCD.TEXT = str_distance sleep(1)