Browse Source

Re-implementation of grab/protocol detection algorithm

master
Carlos Reding 1 year ago
parent
commit
e7c9b60af7
2 changed files with 33 additions and 30 deletions
  1. 1
    0
      pupuicon/translator/_core.py
  2. 32
    30
      srv_controller.py

+ 1
- 0
pupuicon/translator/_core.py View File

@@ -171,6 +171,7 @@ class ProtocolHandler:
self.QueueFile = self._createQueue(self.delay,
UserInstructions.localTime,
UserInstructions.queueTimes)
self.QueueTimes = UserInstructions.queueTimes


class HardwareHandler():

+ 32
- 30
srv_controller.py View File

@@ -1,3 +1,5 @@
#!/bin/python3

import threading, sys, time, queue
from puppeteer import Controller, HardwareTest, TemperatureTest,\
ProtocolTest, ExportData, QueueStatus, CancelProtocol,\
@@ -36,37 +38,35 @@ while True:
# Box_Socket can still be populated in parallel (i.e. to cancel protocol).
try:
if GUI.command.__module__ == 'pupuicon.translator._core':
USR_Instructions = GUI.command
BoxQueue = queue.Queue()
Box = threading.Thread(target=Controller, args=(USR_Instructions,
Box_Socket.Connection,
cancel_switch,
gui_status,
BoxQueue,
protocol_status))
Box.start()
[LiMO, Protocol, QueueFile] = BoxQueue.get()
# Box.join() # Will wait until `target' finishes.
# _AVOID_ at any cost for proper multi-threading.
# Adjust __WAITING_TIME__ as a function of `replicates'.
# WARNING! ASSUMES 10 FPS MODE! (0.1s exposure will be the slowest mode available).
__SHUTTER_SPEED__ = Protocol._device._camera.shutter_speed * 10**-6 # From µS to SECONDS
if Replicates > 1:
__REPLICATE_SCALING_FACTOR__ = 2.0 + __SHUTTER_SPEED__
elif Replicates == 1:
__REPLICATE_SCALING_FACTOR__ = 4.35 + __SHUTTER_SPEED__
__FILTER_SCALING_FACTOR__ = 2.35 + Replicates # 2.35 = all t.sleep() added, 0.75s ~ read/write/processing time
__WAITING_TIME__ = len(Protocol._filters) * __FILTER_SCALING_FACTOR__ + Replicates * __REPLICATE_SCALING_FACTOR__
time.sleep(__WAITING_TIME__) # Setting for dataGrab
if protocol_status.is_set():
# Means dataGrab
ExportData(Protocol, False, QueueFile,
Box_Socket.Connection, gui_status, Test=True)
USR_INSTRUCTIONS = GUI.command
if len(USR_INSTRUCTIONS.QueueTimes) > 1:
# This is a normal protocol...
BoxQueue = queue.Queue()
Box = threading.Thread(target=Controller, args=(USR_INSTRUCTIONS,
Box_Socket.Connection,
cancel_switch,
gui_status,
BoxQueue,
protocol_status))
Box.start()
[LiMO, Protocol, QueueFile] = BoxQueue.get()
elif len(USR_INSTRUCTIONS.QueueTimes) == 1:
# This is a grab...
print("User says: (Flexi)grab data.")
BoxQueue = queue.Queue()
Box = threading.Thread(target=Controller, args=(USR_INSTRUCTIONS,
Box_Socket.Connection,
cancel_switch,
gui_status,
BoxQueue,
protocol_status))
Box.start()
[_, Protocol, _] = BoxQueue.get()
Box.join() # Wait until thread finishes (1 step only).
ExportData(Protocol, False, None, Box_Socket.Connection,
gui_status, Test=True)
protocol_status.clear()
else:
# Means protocol running
continue
except AttributeError:
# __module__ attribute does not exist, therefore
# GUI.command does not contain a protocol.
@@ -89,6 +89,8 @@ while True:
elif GUI.command == "Abort Protocol":
# Turn hardware OFF before cancelling!! otherwise things
# like HEATER can be left ON.
Box._stop()
Box.join()
print("Cancel Protocol.")
if 'LiMO' in locals():
CancelProtocol(with_device=LiMO)

Loading…
Cancel
Save