Commit 28377abd authored by Spencer Du's avatar Spencer Du

update code

parent da9df457
......@@ -57,7 +57,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.combo.addItem(item, self.importbutton)
except:
print("No devices active")
readFile("list_of_devices_currently_active.txt")
readFile("list_of_device(s)_currently_active.txt")
def importbutton(self):
if not os.path.exists("laser.ini"):
......
import paho.mqtt.client as mqtt
from mqtt import *
from mqtt2 import *
import os
import time
import json
......@@ -7,14 +7,15 @@ import json
def start():
try:
os.remove("list_of_devices_currently_active.txt")
print("Awaiting devices to be activated")
os.remove("laserConfig.json")
print("Awaiting device(s) to be activated")
except:
print("Awaiting devices to be activated")
print("Awaiting device(s) to be activated")
start()
devices = list(map(str,input("Devices to be activated: ").split(",")))
devices = list(map(str,input("Device(s) to be activated: ").split(",")))
client = device()
client = embedded()
client.run()
client.loop_start()
......@@ -23,7 +24,7 @@ time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI")
client.subscribe("microscope/light_sheet_microscope/UI")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI")
client.publish("microscope/light_sheet_microscope/UI", json.dumps({"type": "system", "payload":{"name": devices, "cmd": "activating devices"}}, indent=2))
client.publish("microscope/light_sheet_microscope/UI", json.dumps({"type": "system", "payload":{"name": devices, "cmd": "activating device(s)"}}, indent=2))
time.sleep(1)
def active_devices():
......@@ -31,28 +32,28 @@ def active_devices():
device = (item + "Embedded")
deviceImport = __import__(device)
with open("list_of_devices_currently_active.txt", "a+") as myfile:
with open("list_of_device(s)_currently_active.txt", "a+") as myfile:
for item in devices:
myfile.write(item + "\n")
active_devices()
def readFile(fname):
print("List of devices currently active:")
print("List of device(s) currently active:")
try:
with open(fname, "r") as f:
for item in f:
print(item.rstrip("\n"))
except:
print("No devices added yet")
readFile("list_of_devices_currently_active.txt")
print("No device(s) added yet")
readFile("list_of_device(s)_currently_active.txt")
client = device()
client = embedded()
client.run()
client.loop_start()
# client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/445nm")
client.subscribe("microscope/light_sheet_microscope/UI/445nm")
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 = 33
[488nm]
intensity = 8
This diff is collapsed.
{
"laser": [
{
"type": "device",
"payload": {
"name": "laser",
"wavelength": "445nm",
"intensity": "2",
"cmd": "set intensity of laser"
}
}
]
}
\ No newline at end of file
......@@ -5,17 +5,17 @@ from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
class Laser(Actor):
async def handle_message(self, message: Message):
print("Laser")
await asyncio.sleep(2)
# await asyncio.sleep(1)
print("Unitialised")
await asyncio.sleep(2)
# await asyncio.sleep(1)
print("Initialising")
await asyncio.sleep(2)
# await asyncio.sleep(1)
print("Initialised")
await asyncio.sleep(2)
# await asyncio.sleep(1)
print("Configuring")
await asyncio.sleep(2)
# await asyncio.sleep(1)
print("Configured")
await asyncio.sleep(2)
# await asyncio.sleep(1)
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.
......
......@@ -2,7 +2,7 @@ import logging
import paho.mqtt.client as mqtt
import json
class device(mqtt.Client):
class embedded(mqtt.Client):
def on_connect(self, mqtt, obj, flags, rc):
pass
......@@ -14,13 +14,6 @@ class device(mqtt.Client):
print("message qos=", message.qos)
print("message retain flag=", message.retain)
m_in = json.loads(m_decode)
# if m_in["payload"]["name"] == devices:
# print("Laser added" + "\n")
# if m_in["payload"]["cmd"] == "laser turning on":
# laser = ("laserEmbedded")
# laserImport = __import__(laser)
# print("Laser turned on" + "\n")
def run(self):
self.connect("broker.hivemq.com", 1883, 60)
\ No newline at end of file
self.connect("localhost", 1883, 60)
\ No newline at end of file
[mysql]
host = localhost
user = root
passwd = my secret password
db = write-math
[other]
preprocessing_queue = ['preprocessing.scale_and_center', 'preprocessing.dot_reduction', 'preprocessing.connect_lines']
use_anonymous = True
import json
new_dictionary = {"hi": "new"}
with open('python_dictionary.json','a') as f:
str = json.dumps(new_dictionary).replace('{', ',', 1)
f.seek(0,2)
f.write(str)
\ No newline at end of file
[
{
"type": "device",
"payload": {
"name": "laser",
"wavelength": "445nm",
"455nm intensity": "textboxValue",
"cmd": "set intensity of laser"
}
},
{
"type": "device",
"payload": {
"name": "laser",
"wavelength": "488nm",
"488nm intensity": "textboxValue2",
"cmd": "set intensity of laser"
}
}
]
\ No newline at end of file
import json
books_dictionary = {"laser": []}
books = books_dictionary["laser"]
books.append({"type": "device", "payload":{"name": "laser", "wavelength": "445nm", "455nm intensity": "textboxValue", "cmd": "set intensity of laser"}})
with open('laserConfig.json', 'w') as f:
json.dump(books, f, indent=2)
books.append({"type": "device", "payload":{"name": "laser", "wavelength": "488nm", "488nm intensity": "textboxValue2", "cmd": "set intensity of laser"}})
with open('laserConfig.json', 'w+') as f:
json.dump(books, f, indent=2)
\ 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