laser_embedded.py 1.13 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
from mqtt2 import *
Spencer Du's avatar
Spencer Du committed
5

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

Spencer Du's avatar
Spencer Du committed
29 30 31
def subscribe(): 
    client = embedded()
    client.run()
Spencer Du's avatar
Spencer Du committed
32

Spencer Du's avatar
Spencer Du committed
33 34
    client.loop_start()
    client.subscribe("microscope/light_sheet_microscope/UI/laser/#")
Spencer Du's avatar
Spencer Du committed
35
subscribe()