Commit 2e9070f9 authored by Spencer Du's avatar Spencer Du

off button added

parent a5810987
[laser]
name=laser
[cameras]
name=cameras
\ No newline at end of file
......@@ -87,10 +87,12 @@ class Ui_Laser(object):
self.gridLayout.addWidget(self.label_5, 2, 8, 1, 2)
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setCheckable(True)
self.pushButton_4.clicked.connect(self.btnstate4)
self.pushButton_4.setObjectName("pushButton_4")
self.gridLayout.addWidget(self.pushButton_4, 3, 6, 1, 2)
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setCheckable(True)
self.pushButton_5.clicked.connect(self.btnstate5)
self.pushButton_5.setObjectName("pushButton_5")
self.gridLayout.addWidget(self.pushButton_5, 3, 8, 1, 2)
self.label_16 = QtWidgets.QLabel(self.centralwidget)
......@@ -143,6 +145,7 @@ class Ui_Laser(object):
self.gridLayout.addWidget(self.verticalSlider_3, 6, 4, 1, 1)
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setCheckable(True)
self.pushButton_3.clicked.connect(self.btnstate3)
self.pushButton_3.setObjectName("pushButton_3")
self.gridLayout.addWidget(self.pushButton_3, 3, 4, 1, 2)
self.label_15 = QtWidgets.QLabel(self.centralwidget)
......@@ -164,6 +167,7 @@ class Ui_Laser(object):
self.gridLayout.addWidget(self.pushButton_12, 9, 6, 1, 2)
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setCheckable(True)
self.pushButton_2.clicked.connect(self.btnstate2)
self.pushButton_2.setObjectName("pushButton_2")
self.gridLayout.addWidget(self.pushButton_2, 3, 2, 1, 2)
self.verticalSlider_2 = QtWidgets.QSlider(self.centralwidget)
......@@ -179,6 +183,7 @@ class Ui_Laser(object):
self.gridLayout.addWidget(self.pushButton_13, 9, 8, 1, 2)
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_6.setCheckable(True)
self.pushButton_6.clicked.connect(self.btnstate6)
self.pushButton_6.setObjectName("pushButton_6")
self.gridLayout.addWidget(self.pushButton_6, 3, 10, 1, 2)
self.label_10 = QtWidgets.QLabel(self.centralwidget)
......@@ -192,6 +197,10 @@ class Ui_Laser(object):
self.pushButton_8.setChecked(True)
self.pushButton_8.setObjectName("pushButton_8")
self.gridLayout.addWidget(self.pushButton_8, 1, 0, 1, 2)
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_7.clicked.connect(self.stop)
self.pushButton_7.setObjectName("pushButton_7")
self.gridLayout.addWidget(self.pushButton_7, 1, 2, 1, 2)
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setObjectName("label_8")
self.gridLayout.addWidget(self.label_8, 4, 0, 1, 1)
......@@ -202,7 +211,6 @@ class Ui_Laser(object):
self.statusbar = QtWidgets.QStatusBar(Laser)
self.statusbar.setObjectName("statusbar")
Laser.setStatusBar(self.statusbar)
self.retranslateUi(Laser)
QtCore.QMetaObject.connectSlotsByName(Laser)
......@@ -212,6 +220,7 @@ class Ui_Laser(object):
self.pushButton_9.clicked.connect(self.printValue)
else:
if self.pushButton.isChecked():
self.pushButton_10.clicked.connect(self.printValue2)
config = configparser.RawConfigParser()
config.read("laser.ini")
......@@ -222,6 +231,120 @@ class Ui_Laser(object):
self.pushButton_9.clicked.disconnect(self.printValue)
self.verticalSlider.setValue(0)
self.lineEdit.clear()
def btnstate2(self):
if not os.path.exists("laser.ini"):
if self.pushButton_2.isChecked():
self.pushButton_10.clicked.connect(self.printValue2)
else:
if self.pushButton_2.isChecked():
self.pushButton_10.clicked.connect(self.printValue2)
config = configparser.RawConfigParser()
config.read("laser.ini")
try:
self.verticalSlider_2.setValue(config.getint("488nm", "intensity"))
self.lineEdit_2.setText(str(config.getint("488nm", "intensity")))
except Exception as e:
pass
else:
self.pushButton_10.clicked.connect(self.printValue2)
self.pushButton_10.clicked.disconnect(self.printValue2)
self.verticalSlider_2.setValue(0)
self.lineEdit_2.clear()
def btnstate3(self):
if not os.path.exists("laser.ini"):
if self.pushButton_3.isChecked():
self.pushButton_11.clicked.connect(self.printValue3)
else:
if self.pushButton_3.isChecked():
self.pushButton_11.clicked.connect(self.printValue3)
config = configparser.RawConfigParser()
config.read("laser.ini")
try:
self.verticalSlider_3.setValue(config.getint("515nm", "intensity"))
self.lineEdit_3.setText(str(config.getint("515nm", "intensity")))
except Exception as e:
pass
else:
self.pushButton_11.clicked.connect(self.printValue3)
self.pushButton_11.clicked.disconnect(self.printValue3)
self.verticalSlider_3.setValue(0)
self.lineEdit_3.clear()
def btnstate4(self):
if not os.path.exists("laser.ini"):
if self.pushButton_4.isChecked():
self.pushButton_12.clicked.connect(self.printValue4)
else:
if self.pushButton_4.isChecked():
self.pushButton_12.clicked.connect(self.printValue4)
config = configparser.RawConfigParser()
config.read("laser.ini")
try:
self.verticalSlider_4.setValue(config.getint("561nm", "intensity"))
self.lineEdit_4.setText(str(config.getint("561nm", "intensity")))
except Exception as e:
pass
else:
self.pushButton_12.clicked.connect(self.printValue4)
self.pushButton_12.clicked.disconnect(self.printValue4)
self.verticalSlider_4.setValue(0)
self.lineEdit_4.clear()
def btnstate5(self):
if not os.path.exists("laser.ini"):
if self.pushButton_5.isChecked():
self.pushButton_13.clicked.connect(self.printValue5)
else:
if self.pushButton_5.isChecked():
self.pushButton_13.clicked.connect(self.printValue5)
config = configparser.RawConfigParser()
config.read("laser.ini")
try:
self.verticalSlider_5.setValue(config.getint("594nm", "intensity"))
self.lineEdit_5.setText(str(config.getint("594nm", "intensity")))
except Exception as e:
pass
else:
self.pushButton_13.clicked.connect(self.printValue5)
self.pushButton_13.clicked.disconnect(self.printValue5)
self.verticalSlider_5.setValue(0)
self.lineEdit_5.clear()
def btnstate6(self):
if not os.path.exists("laser.ini"):
if self.pushButton_6.isChecked():
self.pushButton_14.clicked.connect(self.printValue6)
else:
if self.pushButton_6.isChecked():
self.pushButton_14.clicked.connect(self.printValue6)
config = configparser.RawConfigParser()
config.read("laser.ini")
try:
self.verticalSlider_6.setValue(config.getint("638nm", "intensity"))
self.lineEdit_6.setText(str(config.getint("638nm", "intensity")))
except Exception as e:
pass
else:
self.pushButton_14.clicked.connect(self.printValue6)
self.pushButton_14.clicked.disconnect(self.printValue6)
self.verticalSlider_6.setValue(0)
self.lineEdit_6.clear()
# else:
# try:
......@@ -309,21 +432,25 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
try:
config.add_section("445nm")
except Exception as e:
pass
config.set("445nm", "intensity", textboxValue)
config.add_section("Subscriptions")
config.set("Subscriptions", "445nm", "microscope/light_sheet_microscope/UI/laser/445nm")
config.write(f)
def printValue2(self):
if not os.path.exists("laser.ini"):
textboxValue2 = self.lineEdit.text()
textboxValue2 = self.lineEdit_2.text()
if self.lineEdit_2.text() == "":
self.verticalSlider_2.setValue(0)
else:
self.verticalSlider_2.setValue(int(textboxValue2))
client = device()
client.run()
client.loop_start()
print("\n" + "Connected to broker")
time.sleep(1)
......@@ -333,7 +460,7 @@ class Ui_Laser(object):
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()
print("Intensity: " + textboxValue2)
config = configparser.RawConfigParser()
......@@ -365,13 +492,17 @@ class Ui_Laser(object):
client.loop_stop()
print("Intensity: " + textboxValue2)
config = configparser.RawConfigParser()
config.read("laser.ini")
f = open("laser.ini", "w")
try:
config.add_section("488nm")
except Exception as e:
pass
config.set("488nm", "intensity", textboxValue2)
config.add_section("Subscriptions")
config.set("Subscriptions", "488nm", "microscope/light_sheet_microscope/UI/laser/488nm")
config.write(f)
......@@ -385,19 +516,18 @@ class Ui_Laser(object):
client = device()
client.run()
client.loop_start()
print("\n" + "Connected to broker")
time.sleep(1)
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))
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()
print("Intensity: " + textboxValue3)
print("Intensity: " + textboxValue3)
config = configparser.RawConfigParser()
f = open("laser.ini", "w")
......@@ -432,8 +562,13 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
config.set("515nm", "intensity", textboxValue3)
config.set("Subscriptions", "515nm", "microscope/light_sheet_microscope/UI/laser/515nm")
try:
config.add_section("515nm")
except Exception as e:
pass
config.set("515nm", "intensity", textboxValue)
config.add_section("Subscriptions")
config.set("Subscriptions", "515nm", "microscope/light_sheet_microscope/UI/laser/445nm")
config.write(f)
def printValue4(self):
......@@ -493,7 +628,12 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
try:
config.add_section("561nm")
except Exception as e:
pass
config.set("561nm", "intensity", textboxValue4)
config.add_section("Subscriptions")
config.set("Subscriptions", "561nm", "microscope/light_sheet_microscope/UI/laser/561nm")
config.write(f)
......@@ -554,6 +694,10 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
try:
config.add_section("594nm")
except Exception as e:
pass
config.set("594nm", "intensity", textboxValue5)
config.set("Subscriptions", "594nm", "microscope/light_sheet_microscope/UI/laser/594nm")
config.write(f)
......@@ -587,6 +731,7 @@ class Ui_Laser(object):
f = open("laser.ini", "w")
config.add_section("638nm")
config.set("638nm", "intensity", textboxValue6)
config.add_section("Subscriptions")
config.set("Subscriptions", "638nm", "microscope/light_sheet_microscope/UI/laser/638nm")
config.write(f)
......@@ -615,11 +760,30 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
config.add_section("638nm")
try:
config.add_section("638nm")
except Exception as e:
pass
config.set("638nm", "intensity", textboxValue6)
config.set("Subscriptions", "638nm", "microscope/light_sheet_microscope/UI/laser/638nm")
config.write(f)
config.write(f)
def stop(self):
client = device()
client.run()
client.loop_start()
print("\n" + "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", "cmd": "device turning off"}}, indent=2))
time.sleep(1)
client.loop_stop()
self.pushButton_8.setChecked(False)
print("Laser turned off")
def retranslateUi(self, Laser):
_translate = QtCore.QCoreApplication.translate
Laser.setWindowTitle(_translate("Laser", "MainWindow"))
......@@ -657,6 +821,7 @@ class Ui_Laser(object):
self.label_10.setText(_translate("Laser", "0"))
self.label_12.setText(_translate("Laser", "100"))
self.pushButton_8.setText(_translate("Laser", "ON"))
self.pushButton_7.setText(_translate("Laser", "OFF"))
self.label_8.setText(_translate("Laser", "100"))
self.label_11.setText(_translate("Laser", "100"))
......
......@@ -2,11 +2,6 @@ import random
import asyncio
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
from mqtt2 import *
from pynq.overlays.base import BaseOverlay
from pynq.lib import LED, Switch, Button
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.on()
class Laser(Actor):
async def handle_message(self, message: Message):
......
import logging
import paho.mqtt.client as mqtt
import json
from pynq.overlays.base import BaseOverlay
from pynq.lib import LED, Switch, Button
# from pynq.overlays.base import BaseOverlay
# from pynq.lib import LED, Switch, Button
import time
class embedded(mqtt.Client):
......@@ -17,47 +17,47 @@ class embedded(mqtt.Client):
print("message qos=", message.qos)
print("message retain flag=", message.retain)
m_in = json.loads(m_decode)
if message.topic == "microscope/light_sheet_microscope/UI/laser/445nm":
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
# if message.topic == "microscope/light_sheet_microscope/UI/laser/445nm":
# base = BaseOverlay("base.bit")
# led0 = base.leds[0]
# for i in range(20):
# led0.toggle()
# time.sleep(.1)
if message.topic == "microscope/light_sheet_microscope/UI/laser/488nm":
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
# if message.topic == "microscope/light_sheet_microscope/UI/laser/488nm":
# base = BaseOverlay("base.bit")
# led0 = base.leds[0]
# for i in range(20):
# led0.toggle()
# time.sleep(.1)
if message.topic == "microscope/light_sheet_microscope/UI/laser/515nm":
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
# if message.topic == "microscope/light_sheet_microscope/UI/laser/515nm":
# base = BaseOverlay("base.bit")
# led0 = base.leds[0]
# for i in range(20):
# led0.toggle()
# time.sleep(.1)
if message.topic == "microscope/light_sheet_microscope/UI/laser/561nm":
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
# if message.topic == "microscope/light_sheet_microscope/UI/laser/561nm":
# base = BaseOverlay("base.bit")
# led0 = base.leds[0]
# for i in range(20):
# led0.toggle()
# time.sleep(.1)
if message.topic == "microscope/light_sheet_microscope/UI/laser/594nm":
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
# if message.topic == "microscope/light_sheet_microscope/UI/laser/594nm":
# base = BaseOverlay("base.bit")
# led0 = base.leds[0]
# for i in range(20):
# led0.toggle()
# time.sleep(.1)
if message.topic == "microscope/light_sheet_microscope/UI/laser/638nm":
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
# if message.topic == "microscope/light_sheet_microscope/UI/laser/638nm":
# base = BaseOverlay("base.bit")
# led0 = base.leds[0]
# for i in range(20):
# led0.toggle()
# time.sleep(.1)
def run(self):
self.connect("broker.hivemq.com", 1883, 60)
\ 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