Commit 8dd224f5 authored by Spencer Du's avatar Spencer Du

update code

parent 04cd2403
......@@ -46,6 +46,4 @@ def readFile(fname):
print(item.rstrip("\n"))
except:
print("No device(s) added yet")
readFile("list_of_device(s)_currently_active.txt")
client.loop_forever()
\ No newline at end of file
readFile("list_of_device(s)_currently_active.txt")
\ No newline at end of file
......@@ -362,10 +362,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "445nm", "intensity": textboxValue, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/445nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/445nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/445nm")
client.publish("microscope/light_sheet_microscope/UI/laser/445nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "445nm", "intensity": textboxValue, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -394,10 +394,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "488nm", "intensity": textboxValue2, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/488nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/488nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/488nm")
client.publish("microscope/light_sheet_microscope/UI/laser/488nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "488nm", "intensity": textboxValue2, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -424,10 +424,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "488nm", "intensity": textboxValue2, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/488nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/488nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/488nm")
client.publish("microscope/light_sheet_microscope/UI/laser/488nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "488nm", "intensity": textboxValue2, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -457,9 +457,9 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/515nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/515nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/515nm")
client.publish("microscope/light_sheet_microscope/UI/515nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "515nm", "intensity": textboxValue3, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -487,10 +487,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "515nm", "intensity": textboxValue3, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/515nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/515nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/515nm")
client.publish("microscope/light_sheet_microscope/UI/laser/515nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "515nm", "intensity": textboxValue3, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -519,10 +519,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "561nm", "intensity": textboxValue4, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/561nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/561nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/561nm")
client.publish("microscope/light_sheet_microscope/UI/laser/561nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "561nm", "intensity": textboxValue4, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -549,10 +549,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "561nm", "intensity": textboxValue4, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/561nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/561nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/561nm")
client.publish("microscope/light_sheet_microscope/UI/laser/561nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "561nm", "intensity": textboxValue4, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -581,10 +581,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "594nm", "intensity": textboxValue5, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/594nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/594nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/594nm")
client.publish("microscope/light_sheet_microscope/UI/laser/594nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "594nm", "intensity": textboxValue5, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -611,10 +611,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "594nm", "intensity": textboxValue5, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/594nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/594nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/594nm")
client.publish("microscope/light_sheet_microscope/UI/laser/594nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "594nm", "intensity": textboxValue5, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -643,10 +643,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "638nm", "intensity": textboxValue6, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/638nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/638nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/638nm")
client.publish("microscope/light_sheet_microscope/UI/laser/638nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "638nm", "intensity": textboxValue6, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......@@ -673,10 +673,10 @@ class Ui_Laser(object):
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "638nm", "intensity": textboxValue6, "cmd": "set intensity of laser"}}, indent=2))
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/laser/638nm")
client.subscribe("microscope/light_sheet_microscope/UI/laser/638nm")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser/638nm")
client.publish("microscope/light_sheet_microscope/UI/laser/638nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "638nm", "intensity": textboxValue6, "cmd": "set intensity of laser"}}, indent=2))
time.sleep(1)
client.loop_stop()
......
......@@ -2,6 +2,7 @@ import random
import asyncio
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
import configparser as configparser
import os
class Laser(Actor):
async def handle_message(self, message: Message):
......@@ -19,23 +20,18 @@ class Laser(Actor):
# await asyncio.sleep(1)
await message.sender.tell(DataMessage(data="Hello World Im a laser!" +"\n", sender=self))
# parser = configparser.ConfigParser()
# parser.read("laser.ini")
# subscriptions = dict(parser.items("Subscriptions"))
# print(subscriptions)
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)
parser = configparser.ConfigParser()
parser.read("laser.ini")
asyncio.get_event_loop().run_until_complete(main())
subscriptions = dict(parser.items("Subscriptions"))
print("Subscribing to topics", subscriptions)
client.subscribe(subscriptions)
asyncio.get_event_loop().run_until_complete(main())
# if os.path.exists("laser.ini"):
# parser = configparser.ConfigParser()
# parser.read("laser.ini")
# subscriptions = dict(parser.items("Subscriptions"))
# print("Subscribing to topics", subscriptions)
# client.subscribe(subscriptions)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment