Commit a5810987 authored by Spencer Du's avatar Spencer Du

Code allowing me to turn on and off a laser and set the value for the laser slider

parent 85e136dc
......@@ -41,7 +41,7 @@ class MainWindow(QtWidgets.QMainWindow):
startMenu = menubar.addMenu("Start")
stopMenu = menubar.addMenu("Stop")
startMenu.triggered.connect(self.start)
# startMenu.triggered.connect(self.start)
# pybutton = QPushButton("Run", self)
# pybutton.resize(25,15)
......
[laser]
name=laser
[cameras]
name=cameras
\ No newline at end of file
......@@ -207,13 +207,51 @@ class Ui_Laser(object):
QtCore.QMetaObject.connectSlotsByName(Laser)
def btnstate(self):
if self.pushButton.isChecked():
self.pushButton_9.clicked.connect(self.printValue)
self.pushButton_10.clicked.connect(self.printValue2)
self.pushButton_11.clicked.connect(self.printValue3)
self.pushButton_12.clicked.connect(self.printValue4)
self.pushButton_13.clicked.connect(self.printValue5)
self.pushButton_14.clicked.connect(self.printValue6)
if not os.path.exists("laser.ini"):
if self.pushButton.isChecked():
self.pushButton_9.clicked.connect(self.printValue)
else:
if self.pushButton.isChecked():
config = configparser.RawConfigParser()
config.read("laser.ini")
self.verticalSlider.setValue(config.getint("445nm", "intensity"))
self.lineEdit.setText(str(config.getint("445nm", "intensity")))
else:
self.pushButton_9.clicked.connect(self.printValue)
self.pushButton_9.clicked.disconnect(self.printValue)
self.verticalSlider.setValue(0)
self.lineEdit.clear()
# else:
# try:
# self.pushButton_9.clicked.disconnect(self.printValue)
# self.verticalSlider.setValue(0)
# self.lineEdit.clear()
# except Exception as e:
# config = configparser.RawConfigParser()
# config.read("laser.ini")
# self.verticalSlider.setValue(config.getint("445nm", "intensity"))
# self.lineEdit.setText(str(config.getint("445nm", "intensity")))
# except:
# if os.path.exists("laser.ini"):
# try:
# config = configparser.RawConfigParser()
# config.read("laser.ini")
# self.verticalSlider.setValue(config.getint("445nm", "intensity"))
# self.lineEdit.setText(str(config.getint("445nm", "intensity")))
# except Exception as e:
# print("Laser config does not exist")
# self.pushButton_10.clicked.connect(self.printValue2)
# self.pushButton_11.clicked.connect(self.printValue3)
# self.pushButton_12.clicked.connect(self.printValue4)
# self.pushButton_13.clicked.connect(self.printValue5)
# self.pushButton_14.clicked.connect(self.printValue6)
def printValue(self):
if not os.path.exists("laser.ini"):
......@@ -271,7 +309,6 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
config.add_section("445nm")
config.set("445nm", "intensity", textboxValue)
config.set("Subscriptions", "445nm", "microscope/light_sheet_microscope/UI/laser/445nm")
config.write(f)
......@@ -333,8 +370,7 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
config.add_section("488nm")
config.set("488nm", "intensity", textboxValue2)
config.set("Subscriptions", "488nm", "microscope/light_sheet_microscope/UI/laser/488nm")
config.write(f)
......@@ -396,7 +432,6 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
config.add_section("515nm")
config.set("515nm", "intensity", textboxValue3)
config.set("Subscriptions", "515nm", "microscope/light_sheet_microscope/UI/laser/515nm")
config.write(f)
......@@ -458,7 +493,6 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
config.add_section("561nm")
config.set("561nm", "intensity", textboxValue4)
config.set("Subscriptions", "561nm", "microscope/light_sheet_microscope/UI/laser/561nm")
config.write(f)
......@@ -520,7 +554,6 @@ class Ui_Laser(object):
config.read("laser.ini")
f = open("laser.ini", "w")
config.add_section("594nm")
config.set("594nm", "intensity", textboxValue5)
config.set("Subscriptions", "594nm", "microscope/light_sheet_microscope/UI/laser/594nm")
config.write(f)
......
......@@ -2,6 +2,11 @@ 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
import time
class embedded(mqtt.Client):
def on_connect(self, mqtt, obj, flags, rc):
......@@ -14,6 +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/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/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/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
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QWidget, QPushButton, QAction
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QIcon
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(300, 100))
self.setWindowTitle("PyQt menu example - pythonprogramminglanguage.com")
# Add button widget
pybutton = QPushButton('Pyqt', self)
pybutton.clicked.connect(self.clickMethod)
pybutton.resize(100,32)
pybutton.move(130, 30)
pybutton.setToolTip('This is a tooltip message.')
# Create new action
newAction = QAction(QIcon('new.png'), '&New', self)
newAction.setShortcut('Ctrl+N')
newAction.setStatusTip('New document')
newAction.triggered.connect(self.newCall)
# Create new action
openAction = QAction(QIcon('open.png'), '&Open', self)
openAction.setShortcut('Ctrl+O')
openAction.setStatusTip('Open document')
openAction.triggered.connect(self.openCall)
# Create exit action
exitAction = QAction(QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.exitCall)
# Create menu bar and add action
menuBar = self.menuBar()
fileMenu = menuBar.addMenu('&File')
fileMenu.addAction(newAction)
fileMenu.addAction(openAction)
fileMenu.addAction(exitAction)
def openCall(self):
print('Open')
def newCall(self):
print('New')
def exitCall(self):
print('Exit app')
def clickMethod(self):
print('PyQt')
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )
\ No newline at end of file
import aiohttp
from aiohttp import web
from actorio import Actor, EndMainLoop
import asyncio
class Client(Actor):
def __init__(self, websocket: web.WebSocketResponse):
self.websocket = websocket
super().__init__()
# Here we define an input task handler,
# It will be called each time its registered event happens.
# The resulting `asyncio.Task` object will be passed as argument,
# this way, the handler can deal with any exception raised during event collection
async def handle_websocket_event(self, task: asyncio.Task):
try:
msg = task.result()
except Exception as e:
# In case of any exception, we just stop the Actor
self.logger.exception(e)
raise EndMainLoop()
if msg.type == aiohttp.WSMsgType.TEXT:
# if we receive text, we just send it back
# We could also just send a message to our inbox
await self.websocket.send_str(msg.data)
else:
# any other request just stops the Actor
raise EndMainLoop()
async def mainloop_setup(self):
self.register_input_task(self.websocket.receive, self.handle_websocket_event)
await super().mainloop_setup()
async def websocket_handler(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
client_actor = Client(websocket=ws)
async with client_actor:
# We until the client's mainloop ends
await client_actor
return ws
app = web.Application()
app.add_routes([web.get('/', websocket_handler)])
web.run_app(app)
\ No newline at end of file
from pynq.overlays.base import BaseOverlay
from pynq.lib import LED, Switch, Button
import time
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
\ No newline at end of file
for i in '123':
print("guru99")
\ 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