aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/lock_eit.py57
1 files changed, 33 insertions, 24 deletions
diff --git a/examples/lock_eit.py b/examples/lock_eit.py
index 91ae6f4..31d1e72 100644
--- a/examples/lock_eit.py
+++ b/examples/lock_eit.py
@@ -7,6 +7,7 @@ import matplotlib.pyplot as plt
import asyncio
import time
+import qolab.gui.web as gui
from qolab.hardware import BasicInstrument
from qolab.hardware.scope import SDS1104X
from qolab.hardware.rf_generator import AgilentE8257D
@@ -54,7 +55,7 @@ def adjustRFandLog(apparatus):
scope = apparatus.scope
rfgen = apparatus.rfgen
pid = apparatus.pid
- log = apparatus.log
+ log = apparatus.gui_log.traces
ch1=scope.getTrace(1, decimate=False)
err = np.mean(ch1.y.values)
@@ -107,11 +108,14 @@ freqZero = 6834686400
freqDeltaM2 = 6835387100
async def main():
+ task_wp_update_loop = asyncio.create_task(update_webpage_loop(update_interval=1))
apparatus.config['Device type'] = 'QOL VAMPIRE HighPower magnetometer'
apparatus.config['Device model'] = 'v0.1'
apparatus.config['FnamePrefix'] = 'locked_magnetometer'
apparatus.config['SavePath'] = '/mnt/qol_grp_data/data.VAMPIRE.HighPower'
+ apparatus.gui_log = gui.QOLTimeLog(a=wp)
+ task_gui_log_update_loop = asyncio.create_task(apparatus.gui_log.update_loop(update_interval=5))
print("testing")
rm = pyvisa.ResourceManager()
@@ -145,56 +149,65 @@ async def main():
print('========== Initial lock ===========')
apparatus.state = 'Initial lock'
update_webpage(apparatus=apparatus)
- apparatus.log = initLog()
+ apparatus.gui_log.traces = initLog()
apparatus.logFileName = None
wp.data['log_file_name'] = apparatus.logFileName
apparatus.pid.reset()
apparatus.runStatus = True
- res = await asyncio.gather( feedbackLoop(apparatus, nsteps=100), updateLogPlotLoop(apparatus), updateLogFileLoop(apparatus) )
- print(apparatus.logFileName)
- updateLogPlot(apparatus)
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=100)
+ )
print('========= Long term lock ===========')
apparatus.state = 'Long term lock'
update_webpage(apparatus=apparatus)
- apparatus.log = initLog()
- # apparatus.logFileName = None
- apparatus.logFileName = apparatus.getNextDataFile()
+ apparatus.gui_log.traces = initLog()
+ apparatus.logFileName = None
+ # apparatus.logFileName = apparatus.getNextDataFile()
wp.data['log_file_name'] = apparatus.logFileName
apparatus.pid.reset()
apparatus.runStatus = True
- res = await asyncio.gather( feedbackLoop(apparatus, nsteps=100000), updateLogPlotLoop(apparatus), updateLogFileLoop(apparatus) )
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=10000)
+ # , updateLogPlotLoop(apparatus),
+ # updateLogFileLoop(apparatus)
+ )
print(apparatus.logFileName)
- updateLogPlot(apparatus)
+ # updateLogPlot(apparatus)
# apparatus.log.save(apparatus.logFileName, item_format='.15e')
apparatus.state = 'Done working with hardware'
- update_webpage(apparatus=apparatus)
+ # update_webpage(apparatus=apparatus)
+ task_gui_log_update_loop.cancel()
+ task_wp_update_loop.cancel()
+ print("done")
return(apparatus)
def update_webpage(byWhom=None, apparatus=None):
+ print("updating webpage")
timestr = time.strftime("%a, %d %b %Y, %H:%M:%S", time.localtime())
clock_upd.text = f'Last update at {timestr}'
- try:
- status_line.text = apparatus.state
- except NameError:
- pass
+ # try:
+ # status_line.text = apparatus.state
+ # except NameError:
+ # pass
jp.run_task(wp.update())
+async def update_webpage_loop(update_interval=1):
+ while True:
+ update_webpage()
+ await asyncio.sleep(update_interval)
+
async def getPage():
return wp
async def jp_startup():
jp.run_task(main())
-async def clear_log(self, msg):
- apparatus.log = initLog()
-
-button_classes = 'm-2 p-2 text-red-700 bg-white hover:bg-red-200 hover:text-red-500 border focus:border-red-500 focus:outline-none'
-
if __name__ == '__main__':
wp = jp.WebPage(delete_flag=False)
apparatus = BasicInstrument()
+
d=jp.Div(text='Magnetometer log', a=wp, classes='text-white bg-blue-500 text-center text-xl')
div_status = jp.Div(classes='text-xl flex m0 p-1 space-x-4 bg-gray-300 font-mono', a=wp)
@@ -206,11 +219,7 @@ if __name__ == '__main__':
wp.data['log_file_name'] = None
div_log = jp.Div(classes='flex', a=wp)
- b_clear_log = jp.Button(text='Clear log', a=div_log, classes=button_classes, click=clear_log)
- f = plt.figure()
- log_chart = jp.Matplotlib(a=wp)
- plt.close(f)
# mpl.use("TkAgg")
# apparatus = asyncio.run(main())
jp.justpy(getPage, startup=jp_startup)