Commit 04cd2403 authored by Spencer Du's avatar Spencer Du

update code

parent 07df5a64
......@@ -6,7 +6,7 @@ import json
def start():
try:
os.remove("list_of_devices_currently_active.txt")
os.remove("list_of_device(s)_currently_active.txt")
os.remove("laserConfig.json")
print("Awaiting device(s) to be activated")
except:
......@@ -48,12 +48,4 @@ def readFile(fname):
print("No device(s) added yet")
readFile("list_of_device(s)_currently_active.txt")
client = embedded()
client.run()
# 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")
client.loop_forever()
\ No newline at end of file
[445nm]
intensity = 2
[Subscriptions]
445nm = {"type": "device", "payload": {"name": "laser", "wavelength": "445nm", "intensity": "2", "cmd": "set intensity of laser"}}
488nm = {"type": "device", "payload": {"name": "laser", "wavelength": "488nm", "intensity": "2", "cmd": "set intensity of laser"}}
515nm = {"type": "device", "payload": {"name": "laser", "wavelength": "515nm", "intensity": "2", "cmd": "set intensity of laser"}}
561nm = {"type": "device", "payload": {"name": "laser", "wavelength": "561nm", "intensity": "2", "cmd": "set intensity of laser"}}
594nm = {"type": "device", "payload": {"name": "laser", "wavelength": "594nm", "intensity": "2", "cmd": "set intensity of laser"}}
638nm = {"type": "device", "payload": {"name": "laser", "wavelength": "638nm", "intensity": "2", "cmd": "set intensity of laser"}}
[488nm]
intensity = 2
[515nm]
intensity = 2
[561nm]
intensity = 2
[594nm]
intensity = 2
[638nm]
intensity = 2
......@@ -332,10 +332,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()
......@@ -347,7 +347,7 @@ class Ui_Laser(object):
config.add_section("445nm")
config.set("445nm", "intensity", textboxValue)
config.add_section("Subscriptions")
config.set("Subscriptions", "445nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "445nm", "intensity": textboxValue, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "445nm", "microscope/light_sheet_microscope/UI/laser/445nm")
config.write(f)
else:
......@@ -377,7 +377,7 @@ class Ui_Laser(object):
f = open("laser.ini", "w")
config.add_section("445nm")
config.set("445nm", "intensity", textboxValue)
config.set("Subscriptions", "445nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "445nm", "intensity": textboxValue, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "445nm", "microscope/light_sheet_microscope/UI/laser/445nm")
config.write(f)
def printValue2(self):
......@@ -409,7 +409,7 @@ class Ui_Laser(object):
config.add_section("488nm")
config.set("488nm", "intensity", textboxValue2)
config.add_section("Subscriptions")
config.set("Subscriptions", "488nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "488nm", "intensity": textboxValue2, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "488nm", "microscope/light_sheet_microscope/UI/laser/488nm")
config.write(f)
else:
......@@ -440,7 +440,7 @@ class Ui_Laser(object):
config.add_section("488nm")
config.set("488nm", "intensity", textboxValue2)
config.set("Subscriptions", "488nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "488nm", "intensity": textboxValue2, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "488nm", "microscope/light_sheet_microscope/UI/laser/488nm")
config.write(f)
def printValue3(self):
......@@ -472,7 +472,7 @@ class Ui_Laser(object):
config.add_section("515nm")
config.set("515nm", "intensity", textboxValue3)
config.add_section("Subscriptions")
config.set("Subscriptions", "515nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "515nm", "intensity": textboxValue3, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "515nm", "microscope/light_sheet_microscope/UI/laser/515nm")
config.write(f)
else:
......@@ -502,7 +502,7 @@ class Ui_Laser(object):
f = open("laser.ini", "w")
config.add_section("515nm")
config.set("515nm", "intensity", textboxValue3)
config.set("Subscriptions", "515nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "515nm", "intensity": textboxValue3, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "515nm", "microscope/light_sheet_microscope/UI/laser/515nm")
config.write(f)
def printValue4(self):
......@@ -534,7 +534,7 @@ class Ui_Laser(object):
config.add_section("561nm")
config.set("561nm", "intensity", textboxValue4)
config.add_section("Subscriptions")
config.set("Subscriptions", "561nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "561nm", "intensity": textboxValue4, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "561nm", "microscope/light_sheet_microscope/UI/laser/561nm")
config.write(f)
else:
......@@ -564,7 +564,7 @@ class Ui_Laser(object):
f = open("laser.ini", "w")
config.add_section("561nm")
config.set("561nm", "intensity", textboxValue4)
config.set("Subscriptions", "561nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "561nm", "intensity": textboxValue4, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "561nm", "microscope/light_sheet_microscope/UI/laser/561nm")
config.write(f)
def printValue5(self):
......@@ -596,7 +596,7 @@ class Ui_Laser(object):
config.add_section("594nm")
config.set("594nm", "intensity", textboxValue5)
config.add_section("Subscriptions")
config.set("Subscriptions", "594nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "594nm", "intensity": textboxValue5, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "594nm", "microscope/light_sheet_microscope/UI/laser/594nm")
config.write(f)
else:
......@@ -626,7 +626,7 @@ class Ui_Laser(object):
f = open("laser.ini", "w")
config.add_section("594nm")
config.set("594nm", "intensity", textboxValue5)
config.set("Subscriptions", "594nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "594nm", "intensity": textboxValue5, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "594nm", "microscope/light_sheet_microscope/UI/laser/594nm")
config.write(f)
def printValue6(self):
......@@ -658,7 +658,7 @@ class Ui_Laser(object):
f = open("laser.ini", "w")
config.add_section("638nm")
config.set("638nm", "intensity", textboxValue6)
config.set("Subscriptions", "638nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "638nm", "intensity": textboxValue6, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "638nm", "microscope/light_sheet_microscope/UI/laser/638nm")
config.write(f)
else:
......@@ -688,7 +688,7 @@ class Ui_Laser(object):
f = open("laser.ini", "w")
config.add_section("638nm")
config.set("638nm", "intensity", textboxValue6)
config.set("Subscriptions", "638nm", json.dumps({"type": "device", "payload":{"name": "laser", "wavelength": "638nm", "intensity": textboxValue6, "cmd": "set intensity of laser"}}))
config.set("Subscriptions", "638nm", "microscope/light_sheet_microscope/UI/laser/638nm")
config.write(f)
# def printValue7(self):
......
import random
import asyncio
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
import configparser as configparser
class Laser(Actor):
async def handle_message(self, message: Message):
......@@ -17,10 +18,24 @@ class Laser(Actor):
print("Configured")
# 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)
asyncio.get_event_loop().run_until_complete(main())
\ No newline at end of file
parser = configparser.ConfigParser()
parser.read("laser.ini")
subscriptions = dict(parser.items("Subscriptions"))
print("Subscribing to topics", subscriptions)
client.subscribe(subscriptions)
asyncio.get_event_loop().run_until_complete(main())
import configparser
import os
import configparser as configparser
if not os.path.isfile('example.ini'):
f = open('example.ini', 'w')
parser = configparser.ConfigParser()
parser.read("sample.ini")
config = configparser.RawConfigParser()
section_2 = dict(parser.items("Section2"))
print(section_2["name3"])
print(section_2)
# Please note that using RawConfigParser's set functions, you can assign
# non-string values to keys internally, but will receive an error when
# attempting to write to a file or when you get it in non-raw mode. Setting
# values using the mapping protocol or ConfigParser's set() does not allow
# such assignments to take place.
config.add_section('mysql')
config.set('mysql', 'host', 'localhost')
config.set('mysql', 'user', 'root')
config.set('mysql', 'passwd', 'my secret password')
config.set('mysql', 'db', 'write-math')
config.add_section('other')
config.set('other',
'preprocessing_queue',
['preprocessing.scale_and_center',
'preprocessing.dot_reduction',
'preprocessing.connect_lines'])
config.set('other', 'use_anonymous', True)
# Writing our configuration file to 'example.cfg'
config.write(f)
\ No newline at end of file
[section1]
Name1=Url_1
Name2=Url_2
[Section2]
Name3=Url_3
Name4=Url_4
\ 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