Exemplo n.º 1
0
 def setup_integration_test(self):
     """
     Starts a broker in a different process, and connects this process to it via
     parlay's "setup" method.
     :return:
     """
     try:
         self.broker_process = start_broker()
         for _ in range(_BROKER_SETUP_NUM_RETRIES - 1):
             time.sleep(_BROKER_SETUP_WAIT_TIME)
             try:
                 setup(timeout=_BROKER_SETUP_TIMEOUT_TIME)
             except RuntimeError as _:
                 pass
         time.sleep(_BROKER_SETUP_WAIT_TIME)
         setup(timeout=_BROKER_SETUP_TIMEOUT_TIME)
     except Exception as e:
         self.teardown_integration_test()
         raise e
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

Exemplo n.º 3
0
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)

Exemplo n.º 4
0
"""
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)
"""
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)
Exemplo n.º 7
0
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)