cameras_embedded.py 1.12 KB
Newer Older
Spencer Du's avatar
Spencer Du committed
1
import random
Spencer Du's avatar
Spencer Du committed
2
import asyncio
Spencer Du's avatar
Spencer Du committed
3
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
Spencer Du's avatar
Spencer Du committed
4

Spencer Du's avatar
Spencer Du committed
5 6 7
class Cameras(Actor):
    async def handle_message(self, message: Message):
        print("Cameras")
8
        # await asyncio.sleep(2)
Spencer Du's avatar
Spencer Du committed
9
        print("Unitialised")
10
        # await asyncio.sleep(2)
Spencer Du's avatar
Spencer Du committed
11
        print("Initialising")
12
        # await asyncio.sleep(2)
Spencer Du's avatar
Spencer Du committed
13
        print("Initialised")
14
        # await asyncio.sleep(2)
Spencer Du's avatar
Spencer Du committed
15
        print("Configuring")
16
        # await asyncio.sleep(2)
Spencer Du's avatar
Spencer Du committed
17
        print("Configured")
18
        # await asyncio.sleep(2)
Spencer Du's avatar
Spencer Du committed
19 20 21 22 23 24 25
        await message.sender.tell(DataMessage(data="Hello World Im a camera!" + "\n", sender=self))
async def main():
    # Let's create an instance of a Greeter actor and start it. 
    async with Cameras() as cameras:
        # Then we'll just send it an empty message and wait for a response
        reply : DataMessage = await ask(cameras, Message())
    print(reply.data)
Spencer Du's avatar
Spencer Du committed
26 27 28 29 30 31 32 33 34
asyncio.get_event_loop().run_until_complete(main())

def subscribe(): 
    client = embedded()
    client.run()

    client.loop_start()
    client.subscribe("microscope/light_sheet_microscope/UI/cameras/#")
subscribe()