Commit bddc18b2 authored by Raman's avatar Raman

RamanScanUI also works with the more stable dataqueue setup.

parent 26ef709d
......@@ -208,8 +208,9 @@ class WITecCOM(RamanBase):
while distance > epsxy:# and (lastpos is None or lastpos!=curpos):
curpos = self.getPosition()
distance = max(abs(curpos[0]-x), abs(curpos[1]-y))
if ((time()-t0>0.5) and max(abs(curpos[0]-initpos[0]), abs(curpos[1]-initpos[1]))<epsxy) or (time()-t0>10.):
print("WARNING: signal ignored:", time()-t0, x, y, curpos, initpos)
# if ((time()-t0>0.5) and max(abs(curpos[0]-initpos[0]), abs(curpos[1]-initpos[1]))<epsxy) or (time()-t0>10.):
if ((time()-t0>2) and max(abs(curpos[0]-initpos[0]), abs(curpos[1]-initpos[1]))<epsxy) or (time()-t0>10.):
print("WARNING: signal ignored; time: {} s, x, y: {}, {}, curPos: {}, initPos: {}".format((time()-t0), x, y, curpos, initpos))
sys.stdout.flush()
break
sleep(.01)
......
......@@ -257,4 +257,4 @@ class DataSet(object):
def save(self):
saveData(self, self.fname)
\ No newline at end of file
\ No newline at end of file
......@@ -24,11 +24,15 @@ import cv2
import os
def cv2imread_fix(fname, flags=cv2.IMREAD_COLOR):
with open(fname, "rb") as fp:
cont = fp.read()
img = cv2.imdecode(np.fromstring(cont, dtype=np.uint8), flags)
return img
return None
if not os.path.exists(fname): #This seems to be a source of potential errors. Having these lines here probably aids finding errors for other groups?
print('Error, image file not found\Please check if the used save-Image command returns before the image was fully written to disk.')
return
with open(fname, "rb") as fp:
cont = fp.read()
img = cv2.imdecode(np.fromstring(cont, dtype=np.uint8), flags)
return img
return None
def cv2imwrite_fix(fname, img, params=None):
pathname, ext = os.path.splitext(fname)
......
......@@ -21,10 +21,11 @@ If not, see <https://www.gnu.org/licenses/>.
from PyQt5 import QtCore, QtWidgets
import numpy as np
from multiprocessing import Process, Pipe
from time import sleep, time
from externalmodules import tsp
from multiprocessing import Process, Queue, Event
import queue
from time import sleep, time, localtime, strftime
import datetime
from externalmodules import tsp
import sys
def reorder(points, N=20):
......@@ -45,7 +46,8 @@ def reorder(points, N=20):
assert np.unique(newind).shape[0]==allind.shape[0]
return newind
def scan(name, accu, inttime, positions, controlclass, connection):
def scan(name, accu, inttime, positions, controlclass, dataqueue, stopevent):
with open("ramanscanlog.txt", "a") as fp:
sys.stderr = fp
sys.stdout = fp
......@@ -53,22 +55,20 @@ def scan(name, accu, inttime, positions, controlclass, connection):
ramanctrl = controlclass()
ramanctrl.connect()
ramanctrl.initiateTimeSeriesScan(name, len(positions), accu, inttime)
print("starting Raman Scan at: " + strftime("%d %b %Y %H:%M:%S", localtime()))
for i, p in enumerate(positions):
x, y, z = p
print("time:", time())
print("position:", x, y, z)
print('Measuring particle index {} at location {}, time = {}'.format(i, (x, y, z), strftime("%H:%M:%S", localtime())))
sys.stdout.flush() #remove after testing
ramanctrl.moveToAbsolutePosition(x, y, z)
ramanctrl.nextTimeSeriesScan(i)
if connection.poll():
instruction = connection.recv()
if instruction=="stop":
ramanctrl.disconnect()
return
connection.send(i)
if stopevent.is_set():
ramanctrl.disconnect()
return
dataqueue.put(i)
ramanctrl.disconnect()
while not connection.poll():
sleep(.1)
connection.recv()
class RamanScanUI(QtWidgets.QWidget):
imageUpdate = QtCore.pyqtSignal(name='imageUpdate')
......@@ -148,8 +148,11 @@ class RamanScanUI(QtWidgets.QWidget):
QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
self.timer.stop()
self.connection.send("stop")
# self.connection.send("stop")
self.processstopevent.set()
self.process.join()
self.dataqueue.close()
self.dataqueue.join_thread()
self.view.unblockUI()
else:
return
......@@ -205,9 +208,9 @@ class RamanScanUI(QtWidgets.QWidget):
self.progressbar.setRange(0, len(scanpoints))
self.progressbar.setValue(0)
self.ramanctrl.disconnect()
parent_conn, child_conn = Pipe()
self.connection = parent_conn
self.process = Process(target=scan, args=(self.dataset.name, accu, inttime, scanpoints, self.ramanctrl.__class__, child_conn))
self.processstopevent = Event()
self.dataqueue = Queue()
self.process = Process(target=scan, args=(self.dataset.name, accu, inttime, scanpoints, self.ramanctrl.__class__, self.dataqueue, self.processstopevent))
self.process.start()
self.starttime = time()
self.timer = QtCore.QTimer(self)
......@@ -217,8 +220,11 @@ class RamanScanUI(QtWidgets.QWidget):
@QtCore.pyqtSlot()
def checkOnScan(self):
if self.connection.poll():
i = self.connection.recv()
try:
i = self.dataqueue.get_nowait()
except queue.Empty:
i = -1
if i >= 0:
self.progressbar.setValue(i+1)
self.view.highLightRamanIndex(i+1)
Npoints = len(self.dataset.ramanpoints)
......@@ -228,9 +234,9 @@ class RamanScanUI(QtWidgets.QWidget):
time2go = ttot - timerunning
self.progresstime.setText(self.timelabeltext + str(datetime.timedelta(seconds=round(time2go))))
if i==Npoints-1:
self.connection.send("stop")
self.process.join()
self.connection.close()
self.dataqueue.close()
self.dataqueue.join_thread()
self.dataset.ramanscandone = True
self.view.saveDataSet()
self.view.unblockUI()
......
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