Commit 67c4023b authored by Spencer Du's avatar Spencer Du

update

parent 91b00c18
......@@ -6,6 +6,7 @@ from PyQt5.QtCore import *
from PyQt5 import QtWidgets, uic
from mqtt import *
import json
import time
class MainWindow(QtWidgets.QMainWindow):
def __init__(self,parent = None):
......@@ -50,35 +51,50 @@ class MainWindow(QtWidgets.QMainWindow):
self.mdi.addSubWindow(sub)
sub.show()
print("creating new instance " + self.fileName_UI)
client = device("Device")
client = device()
client.run()
client.loop_start() # start the loop
device_message = self.fileName_UI
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": "device", "payload":{"name": self.fileName_UI, "cmd": "adding device"}}, indent=2))
client.publish("microscope/light_sheet_microscope/UI", json.dumps({"type": "device", "payload":{"name": self.fileName_UI}}, indent=2))
time.sleep(1) # wait
# print("Device added")
client.loop_stop() # stop the loop
print("Device added" + "\n")
# client = mqtt.Client()
# client.connect("broker.hivemq.com",1883,60)
# print("Connecting to broker")
# # client.loop_start()
# time.sleep(1)
# print("Subscribing to topic", "microscope/light_sheet_microscope/UI")
# client.subscribe("microscope/light_sheet_microscope/UI")
# client.on_subscribe = on_subscribe
# print("Publishing message to topic", "microscope/light_sheet_microscope/UI")
# client.publish("microscope/light_sheet_microscope/UI", json.dumps({"type": "device", "payload":{"name": self.fileName_UI}}, indent=2))
# time.sleep(1)
# client.on_message = on_message
# client.loop_stop()
except:
print("creating new instance " + self.fileName_UI)
client = device("Device")
client.run()
client = mqtt.Client()
client.connect("broker.hivemq.com",1883,60)
client.loop_start() # start the loop
device_message = self.fileName_UI
print("Connecting to broker")
# client.loop_start()
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI")
client.subscribe("microscope/light_sheet_microscope/UI")
client.on_subscribe = on_subscribe
print("Publishing message to topic", "microscope/light_sheet_microscope/UI")
client.publish("microscope/light_sheet_microscope/UI", json.dumps({"type": "device", "payload":{"name": self.fileName_UI}}, indent=2))
time.sleep(1) # wait
client.loop_stop() # stop the loop
time.sleep(1)
client.on_message = on_message
client.loop_forever()
print(device_message + ".py " + "file doesn't exist")
print("Device not added")
......
......@@ -2,18 +2,6 @@ import random
import asyncio
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
from mqtt import *
from GUI import *
listofdevices = []
listofdevices.append(self.fileName_UI)
with open("list_of_devices.txt", "a+") as myfile:
for item in listofdevices:
myfile.write(item + " ")
print(item)
print(listofdevices)
print("Device added to list")
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/list_of_devices")
client.subscribe("microscope/light_sheet_microscope/UI/list_of_devices")
......@@ -24,6 +12,8 @@ def readFile(fname):
with open(fname, "r") as f:
for item in f:
print("List of devices added: " + item)
devicesEmbedded = (item + ".py")
de = __import__(devicesEmbedded)
except:
print("No devices added yet")
readFile("list_of_devices.txt")
\ No newline at end of file
import paho.mqtt.client as mqtt
from mqtt2 import *
import time
import json
client = device()
client.run()
time.sleep(1)
client.loop_start() # start the loop
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI")
client.subscribe("microscope/light_sheet_microscope/UI")
client.loop_forever()
\ No newline at end of file
......@@ -5,6 +5,7 @@ from PyQt5.QtCore import *
from PyQt5 import QtWidgets, uic
from mqtt import *
import json
import time
class SubWindow(QWidget):
def __init__(self, parent = None):
......@@ -27,100 +28,36 @@ class SubWindow(QWidget):
client = device("Filter wheel")
client.run()
client.loop_start()
uninitialised_state = "Uninitialised"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "filter wheel", "state": uninitialised_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + uninitialised_state + "\n")
client.loop_start()
initialising_state = "Initialising"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "filter wheel", "state": initialising_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + initialising_state + "\n")
client.loop_start()
initialised_state = "Initialised"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state",
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "filter wheel", "state": initialised_state}})))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + initialised_state + "\n")
client.loop_start()
configuring_state = "Configuring"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "filter wheel", "state": configuring_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + configuring_state + "\n")
client = device()
client.run()
client.loop_start()
configured_state = "Configured"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "filter wheel", "state": configured_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + configured_state + "\n")
client.loop_start()
run_state = "run"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "filter wheel", "state": run_state}}))
client.loop_start() # start the loop
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": "device", "payload":{"name": self.fileName_UI, "cmd": "filter wheel turning on"}}, indent=2))
# print("Device added")
client.loop_stop() # stop the loop
print("Current state = " + run_state + "\n")
self.Button.setStyleSheet("background-color: green")
print("Hello World! Im a filter wheel")
client.loop_start()
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/list_of_devices")
client.subscribe("microscope/light_sheet_microscope/UI/list_of_devices")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/list_of_devices")
client.publish("microscope/light_sheet_microscope/UI/list_of_devices", self.fileName_UI + " added to device list")
time.sleep(1)
client.loop_stop()
listofdevices = []
listofdevices.append(self.fileName_UI)
with open("list_of_devices_currently_active.txt", "a+") as myfile:
for item in listofdevices:
myfile.write(item + ",")
print(item + " added to device list" + "\n" + "\n" + "List of devices currently active")
# listofdevices = []
# listofdevices.append(self.fileName_UI)
# with open("list_of_devices_currently_active.txt", "a+") as myfile:
# for item in listofdevices:
# myfile.write(item + "\n")
# print(item + " added to device list" + "\n" + "\n" + "List of devices currently active")
# def readFile(fname):
# try:
# with open(fname, "r") as f:
# for item in f:
# print(item)
# except:
# print("No devices added yet")
# readFile("list_of_devices_currently_active.txt")
def readFile(fname):
try:
with open(fname, "r") as f:
for item in f:
print("List of devices currently active: " + item + " " )
except:
print("No devices added yet")
readFile("list_of_devices_currently_active.txt")
def off(self):
client = device("Filter wheel")
client.run()
......@@ -130,26 +67,26 @@ class SubWindow(QWidget):
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "filter wheel", "state": "turning off"}}))
print("Device turned off")
print("Device turned off")
self.Button.setStyleSheet("background-color:")
with open("list_of_devices_currently_active.txt", "r") as f:
lines = f.readlines()
with open("list_of_devices_currently_active.txt", "w") as f:
for line in lines:
if line.strip("\n") != "filter wheel":
f.write(line)
print("Filter wheel removed from device list" "\n\n" + "List of devices currently active")
# with open("list_of_devices_currently_active.txt", "r") as f:
# lines = f.readlines()
# with open("list_of_devices_currently_active.txt", "w") as f:
# for line in lines:
# if line.strip("\n") != "laser":
# f.write(line)
# print("Laser removed from device list" + "\n\n" + "List of devices currently active")
# def readFile(fname):
# try:
# with open(fname, "r") as f:
# for item in f:
# print(item)
# except:
# print("No devices added yet")
# readFile("list_of_devices_currently_active.txt")
def readFile(fname):
try:
with open(fname, "r") as f:
for item in f:
print(item)
except:
print("No devices added yet")
readFile("list_of_devices_currently_active.txt")
def closeEvent(self, event):
self.close()
\ No newline at end of file
......@@ -5,6 +5,7 @@ from PyQt5.QtCore import *
from PyQt5 import QtWidgets, uic
from mqtt import *
import json
import time
class SubWindow(QWidget):
def __init__(self, parent = None):
......@@ -27,99 +28,35 @@ class SubWindow(QWidget):
client = device("Laser")
client.run()
client.loop_start()
uninitialised_state = "Uninitialised"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "laser", "state": uninitialised_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + uninitialised_state + "\n")
client = device()
client.run()
client.loop_start()
initialising_state = "Initialising"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "laser", "state": initialising_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + initialising_state + "\n")
client.loop_start()
initialised_state = "Initialised"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state",
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "laser", "state": initialised_state}})))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + initialised_state + "\n")
client.loop_start()
configuring_state = "Configuring"
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "laser", "state": configuring_state}}))
client.loop_start() # start the loop
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": "device", "payload":{"name": self.fileName_UI, "cmd": "laser turning on"}}, indent=2))
# print("Device added")
client.loop_stop() # stop the loop
print("Current state = " + configuring_state + "\n")
client.loop_start()
configured_state = "Configured"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "laser", "state": configured_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + configured_state + "\n")
client.loop_start()
run_state = "run"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "laser", "state": run_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + run_state + "\n")
self.Button.setStyleSheet("background-color: green")
print("Hello World! Im a laser" + "\n")
client.loop_start()
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/list_of_devices")
client.subscribe("microscope/light_sheet_microscope/UI/list_of_devices")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/list_of_devices")
client.publish("microscope/light_sheet_microscope/UI/list_of_devices", self.fileName_UI + " added to device list")
time.sleep(1)
client.loop_stop()
listofdevices = []
listofdevices.append(self.fileName_UI)
with open("list_of_devices_currently_active.txt", "a+") as myfile:
for item in listofdevices:
myfile.write(item + "\n")
print(item + " added to device list" + "\n" + "\n" + "List of devices currently active")
def readFile(fname):
try:
with open(fname, "r") as f:
for item in f:
print(item)
except:
print("No devices added yet")
readFile("list_of_devices_currently_active.txt")
# listofdevices = []
# listofdevices.append(self.fileName_UI)
# with open("list_of_devices_currently_active.txt", "a+") as myfile:
# for item in listofdevices:
# myfile.write(item + "\n")
# print(item + " added to device list" + "\n" + "\n" + "List of devices currently active")
# def readFile(fname):
# try:
# with open(fname, "r") as f:
# for item in f:
# print(item)
# except:
# print("No devices added yet")
# readFile("list_of_devices_currently_active.txt")
def off(self):
client = device("Laser")
......@@ -133,23 +70,23 @@ class SubWindow(QWidget):
print("Device turned off")
self.Button.setStyleSheet("background-color:")
with open("list_of_devices_currently_active.txt", "r") as f:
lines = f.readlines()
with open("list_of_devices_currently_active.txt", "w") as f:
for line in lines:
if line.strip("\n") != "laser":
f.write(line)
print("Laser removed from device list" + "\n\n" + "List of devices currently active")
def readFile(fname):
try:
with open(fname, "r") as f:
for item in f:
print(item)
except:
print("No devices added yet")
readFile("list_of_devices_currently_active.txt")
# with open("list_of_devices_currently_active.txt", "r") as f:
# lines = f.readlines()
# with open("list_of_devices_currently_active.txt", "w") as f:
# for line in lines:
# if line.strip("\n") != "laser":
# f.write(line)
# print("Laser removed from device list" + "\n\n" + "List of devices currently active")
# def readFile(fname):
# try:
# with open(fname, "r") as f:
# for item in f:
# print(item)
# except:
# print("No devices added yet")
# readFile("list_of_devices_currently_active.txt")
def closeEvent(self, event):
self.close()
\ No newline at end of file
......@@ -4,17 +4,18 @@ from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
class Laser(Actor):
async def handle_message(self, message: Message):
print("Unitialised")
await asyncio.sleep(2)
print("Initialising")
await asyncio.sleep(2)
print("Initialised")
await asyncio.sleep(2)
print("Configuring")
await asyncio.sleep(2)
print("Configured")
await asyncio.sleep(2)
await message.sender.tell(DataMessage(data="Hello World Im a laser!", sender=self))
print("Laser actor")
print("Unitialised")
await asyncio.sleep(2)
print("Initialising")
await asyncio.sleep(2)
print("Initialised")
await asyncio.sleep(2)
print("Configuring")
await asyncio.sleep(2)
print("Configured")
await asyncio.sleep(2)
await message.sender.tell(DataMessage(data="Hello World Im a laser!", sender=self))
async def main():
# Let's create an instance of a Greeter actor and start it.
async with Laser() as laser:
......
......@@ -5,12 +5,13 @@ from PyQt5.QtCore import *
from PyQt5 import QtWidgets, uic
from mqtt import *
import json
import time
class SubWindow(QWidget):
def __init__(self, parent = None):
super(SubWindow, self).__init__(parent)
self.setMinimumSize(QSize(300, 200))
label = QLabel("Motorized galvo wheel", self)
label = QLabel("Motorized_galvo_wheel", self)
self.Button = QtWidgets.QPushButton("ON",self)
self.Button.clicked.connect(self.on)
......@@ -21,135 +22,71 @@ class SubWindow(QWidget):
self.Button2.setGeometry(QtCore.QRect(10, 40, 81, 23))
self.Button2.move(120,40)
self.fileName_UI = "motorized galvo wheel"
self.fileName_UI = "motorized_galvo_wheel"
def on(self):
client = device("Motorized galvo wheel")
client = device("Motorized_galvo_wheel")
client.run()
client.loop_start()
uninitialised_state = "Uninitialised"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "motorized galvo wheel", "state": uninitialised_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + uninitialised_state + "\n")
client.loop_start()
initialising_state = "Initialising"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "motorized galvo wheel", "state": initialising_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + initialising_state + "\n")
client.loop_start()
initialised_state = "Initialised"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state",
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "motorized galvo wheel", "state": initialised_state}})))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + initialised_state + "\n")
client.loop_start()
configuring_state = "Configuring"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "motorized galvo wheel", "state": configuring_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + configuring_state + "\n")
client = device()
client.run()
client.loop_start()
configured_state = "Configured"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "motorized galvo wheel", "state": configured_state}}))
time.sleep(1)
client.loop_stop() # stop the loop
print("Current state = " + configured_state + "\n")
client.loop_start()
run_state = "run"
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state")
client.publish("microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "motorized galvo wheel", "state": run_state}}))
client.loop_start() # start the loop
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": "device", "payload":{"name": self.fileName_UI, "cmd": "motorized_galvo_wheel turning on"}}, indent=2))
# print("Device added")
client.loop_stop() # stop the loop
print("Current state = " + run_state + "\n")
self.Button.setStyleSheet("background-color: green")
print("Hello World! Im a motorized galvo wheel")
client.loop_start()
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/list_of_devices")
client.subscribe("microscope/light_sheet_microscope/UI/list_of_devices")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/list_of_devices")
client.publish("microscope/light_sheet_microscope/UI/list_of_devices", self.fileName_UI + " added to device list")
time.sleep(1)
client.loop_stop()
listofdevices = []
listofdevices.append(self.fileName_UI)
with open("list_of_devices_currently_active.txt", "a+") as myfile:
for item in listofdevices:
myfile.write(item + ",")
print(item + " added to device list" + "\n" + "\n" + "List of devices currently active")
def readFile(fname):
try:
with open(fname, "r") as f:
for item in f:
print("List of devices currently active: " + item + "\n" )
except:
print("No devices added yet")
readFile("list_of_devices_currently_active.txt")
# listofdevices = []
# listofdevices.append(self.fileName_UI)
# with open("list_of_devices_currently_active.txt", "a+") as myfile:
# for item in listofdevices:
# myfile.write(item + "\n")
# print(item + " added to device list" + "\n" + "\n" + "List of devices currently active")
# def readFile(fname):
# try:
# with open(fname, "r") as f:
# for item in f:
# print(item)
# except:
# print("No devices added yet")
# readFile("list_of_devices_currently_active.txt")
def off(self):
client = device("Motorized galvo wheel")
client = device("Motorized_galvo_wheel")
client.run()
client.loop_start()
time.sleep(2)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/state")
client.subscribe("microscope/light_sheet_microscope/UI/state")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "motorized galvo wheel", "state": "turning off"}}))
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/state", json.dumps({"type": "device", "payload":{"name": "motorized_galvo_wheel", "state": "turning off"}}))
print("Device turned off")
self.Button.setStyleSheet("background-color:")
with open("list_of_devices_currently_active.txt", "r") as f:
lines = f.readlines()
with open("list_of_devices_currently_active.txt", "w") as f:
for line in lines:
if line.strip("\n") != "motorized galvo wheel":
f.write(line)
print("Motorized galvo wheel removed from device list" "\n\n" + "List of devices currently active")
def readFile(fname):
try:
with open(fname, "r") as f:
for item in f:
print(item)
except:
print("No devices added yet")
readFile("list_of_devices_currently_active.txt")
# with open("list_of_devices_currently_active.txt", "r") as f:
# lines = f.readlines()