Preparing for BEC scans

This commit is contained in:
gac-x05la
2024-09-16 13:54:15 +02:00
parent ddd0d9430e
commit 4463857b6d
2 changed files with 42 additions and 31 deletions

View File

@@ -108,21 +108,21 @@ class aa1Tasks(Device):
EpicsSignal, "FILEWRITE", string=True, kind=Kind.omitted, put_complete=True
)
def launch_script(self, filename: str, task_index: int=4, filetext=None, settle_time=0.5) -> None:
def launch_script(self, filename: str, taskindex: int=4, filetext=None, settle_time=0.5) -> None:
""" Launch a script file that either exists, or is newly created and compiled"""
self.configure({"text": filetext, "filename": filename, "task_index": task_index})
self.configure({"text": filetext, "filename": filename, "taskindex": taskindex})
print("Runscript configured")
self.kickoff().wait()
print("launchScript waited")
def execute(self, text: str, task_index: int = 4, mode: str = 0):
def execute(self, text: str, taskindex: int = 4, mode: str = 0):
"""Run a short text command on the Automation1 controller and wait for
the reply.
"""
logger.info(f"[{self.name}] Launching program execution on task: {task_index}")
self.configure({"text": text, "task_index": task_index, "mode": mode})
logger.info(f"[{self.name}] Launching program execution on task: {taskindex}")
self.configure({"text": text, "taskindex": taskindex, "mode": mode})
self.kickoff().wait()
# Check the result of JIT compilation
@@ -142,21 +142,21 @@ class aa1Tasks(Device):
# Unrolling the configuration dict
text = d.get("text", None)
filename = d.get("filename", None)
task_index = d.get("task_index", 4)
taskindex = d.get("taskindex", 4)
mode = d.get("mode", None)
self._is_stepconfig = d.get("stepper", False)
# Validation
if task_index < 1 or task_index > 31:
raise RuntimeError(f"Invalid task index: {task_index}")
if taskindex < 1 or taskindex > 31:
raise RuntimeError(f"Invalid task index: {taskindex}")
if (text is None) and (filename is None):
raise RuntimeError("Task execution requires either AeroScript text or filename")
# Common operations
old = self.read_configuration()
self.taskIndex.set(task_index).wait()
self.taskIndex.set(taskindex).wait()
self._text_to_execute = None
self._current_task = task_index
self._current_task = taskindex
self.switch.set("Reset").wait()
# Choose the right execution mode
@@ -166,6 +166,14 @@ class aa1Tasks(Device):
logger.info(f"[{self.name}] Preparing for direct text command execution")
if mode is not None:
self._executeMode.set(mode).wait()
# Compile for syntax checking
self.taskIndex.set(taskindex).wait()
self.fileName.set("foobar.ascript").wait()
self._fileWrite.set(text).wait()
self.switch.set("Load").wait()
# Check the result of load
if self._failure.value:
raise RuntimeError("Failed to load script, perhaps a syntax error?")
self._text_to_execute = text
# We only see the result at compilation
elif (filename is not None) and (text in [None, ""]):
@@ -176,18 +184,18 @@ class aa1Tasks(Device):
self._text_to_execute = None
# Check the result of load
if self._failure.value:
raise RuntimeError("Failed to launch task, please check the Aerotech IOC")
raise RuntimeError("Failed to load task, please check the Aerotech IOC")
elif (filename is not None) and (text not in [None, ""]):
logger.info(f"[{self.name}] Preparing to execute text via intermediary file '{filename}'")
# Execute text via intermediate file
self.taskIndex.set(task_index).wait()
self.taskIndex.set(taskindex).wait()
self.fileName.set(filename).wait()
self._fileWrite.set(text).wait()
self.switch.set("Load").wait()
self._text_to_execute = None
# Check the result of load
if self._failure.value:
raise RuntimeError("Failed to launch task, please check the Aerotech IOC")
raise RuntimeError("Failed to load task, please check the Aerotech IOC")
else:
raise RuntimeError("Unsupported filename-text combo")
@@ -201,6 +209,9 @@ class aa1Tasks(Device):
"""Stop the currently selected task"""
self.switch.set("Stop").wait()
def stage(self):
""" Loads the script, ready for execution"""
def kickoff(self, settle_time=0.5) -> DeviceStatus:
"""Execute the script on the configured task"""
if self._is_configured:
@@ -967,7 +978,7 @@ class aa1AxisDriveDataCollection(Device):
Aerotech API allows the simultaneous capture of two signals into the
limited amount of local DriveArray (2-16 MB/axis).
"""
npoints = int(d["npoints"])
npoints = int(d["ntotal"])
trigger = d.get("trigger", DriveDataCaptureTrigger.PsoOutput)
source0 = d.get("source0", DriveDataCaptureInput.PrimaryFeedback)
source1 = d.get("source1", DriveDataCaptureInput.PositionCommand)

View File

@@ -71,7 +71,7 @@ class AerotechAutomation1Test(unittest.TestCase):
# Attempt to run a short test script using the Execute interface (real)
text = "$rreturn[0]=3.141592"
rbv = dev.execute(text, mode="Double", task_index=3)
rbv = dev.execute(text, mode="Double", taskindex=3)
self.assertTrue(dev._executeMode.get() in ["Double", 3], f"Expecting double return type for execution, but got: {dev._executeMode.get()}")
self.assertTrue(dev.taskIndex.get()==3, "Execution must happen on task 3")
@@ -79,7 +79,7 @@ class AerotechAutomation1Test(unittest.TestCase):
# Attempt to run a short test script using the Execute interface (integer)
text = "$ireturn[0]=42"
rbv = dev.execute(text, mode="Int", task_index=4)
rbv = dev.execute(text, mode="Int", taskindex=4)
self.assertTrue(dev.taskIndex.get()==4, "Execution must happen on task 1")
self.assertTrue(rbv=="Result (int): 42", f"Unexpected reply from execution: {rbv}")
@@ -92,7 +92,7 @@ class AerotechAutomation1Test(unittest.TestCase):
MoveRelative($axis, $fDist, $fVelo)
"""
with self.assertRaises(RuntimeError):
rbv = dev.execute(text, task_index=4)
rbv = dev.execute(text, taskindex=4)
# Attempt to run a short motion command using the Execute interface
text = """
@@ -103,7 +103,7 @@ class AerotechAutomation1Test(unittest.TestCase):
MoveLinear($axis, $fDist, $fVelo)
"""
t_start = time()
rbv = dev.execute(text, task_index=4)
rbv = dev.execute(text, taskindex=4)
t_end = time()
t_elapsed = t_end-t_start
self.assertTrue(t_elapsed > 4, f"Motion was expected to take at least 4 seconds, took {t_elapsed}")
@@ -112,7 +112,7 @@ class AerotechAutomation1Test(unittest.TestCase):
# Send another empty program
filename = "unittesting2.ascript"
text = "program\nvar $positions[2] as real\nend"
dev.launch_script(filename, task_index=3, filetext=text)
dev.launch_script(filename, taskindex=3, filetext=text)
dev.complete().wait()
print("TASK: Done testing TASK module!")
@@ -204,7 +204,7 @@ class AerotechAutomation1Test(unittest.TestCase):
$iglobal[1]=420
$rglobal[1]=1.4142
"""
tsk.execute(text, task_index=4)
tsk.execute(text, taskindex=4)
self.assertEqual(420, dev.int1.value, f"Unexpected integer readback , read {dev.int1.value}, expected 420")
self.assertAlmostEqual(1.4142, dev.float1.value, f"Unexpected floating readback , read {dev.float1.value}, expected 1.4142")
@@ -272,7 +272,7 @@ class AerotechAutomation1Test(unittest.TestCase):
print("AX:DDC: Running a partial acquisition (1/3)")
# Configure the DDC for 42 points and start waiting for triggers
cfg = {'npoints': 42, 'trigger': DriveDataCaptureTrigger.PsoEvent}
cfg = {'ntotal': 42, 'trigger': DriveDataCaptureTrigger.PsoEvent}
dev.configure(cfg)
dev.stage()
# Fire 12 triggers and stop the acquisition early
@@ -293,7 +293,7 @@ class AerotechAutomation1Test(unittest.TestCase):
print("AX:DDC: Running an overruning acquisition (2/3)")
# Configure the DDC for 16 points and start waiting for triggers
cfg = {'npoints': 16, 'trigger': DriveDataCaptureTrigger.PsoEvent}
cfg = {'ntotal': 16, 'trigger': DriveDataCaptureTrigger.PsoEvent}
dev.configure(cfg)
dev.stage()
num = dev.nsamples_rbv.get()
@@ -315,7 +315,7 @@ class AerotechAutomation1Test(unittest.TestCase):
print("AX:DDC: Trying to record some noise on the analog input (3/3)")
cfg = {'npoints': 36, 'trigger': DriveDataCaptureTrigger.PsoEvent, 'source1': DriveDataCaptureInput.AnalogInput0}
cfg = {'ntotal': 36, 'trigger': DriveDataCaptureTrigger.PsoEvent, 'source1': DriveDataCaptureInput.AnalogInput0}
dev.configure(cfg)
dev.stage()
num = dev.nsamples_rbv.get()
@@ -377,7 +377,7 @@ class AerotechAutomation1Test(unittest.TestCase):
# Configure DDC
npoints = 720 / 2.0
cfg = {'npoints': npoints+100, 'trigger': DriveDataCaptureTrigger.PsoOutput}
cfg = {'ntotal': npoints+100, 'trigger': DriveDataCaptureTrigger.PsoOutput}
ddc.configure(cfg)
ddc.stage()
npoints_rbv = ddc.nsamples_rbv.value
@@ -402,7 +402,7 @@ class AerotechAutomation1Test(unittest.TestCase):
# Configure DDC
npoints = 3 * 720 / 1.8
cfg = {'npoints': npoints+100, 'trigger': DriveDataCaptureTrigger.PsoOutput}
cfg = {'ntotal': npoints+100, 'trigger': DriveDataCaptureTrigger.PsoOutput}
ddc.configure(cfg)
ddc.stage()
npoints_rbv = ddc.nsamples_rbv.value
@@ -446,7 +446,7 @@ class AerotechAutomation1Test(unittest.TestCase):
# Configure DDC
npoints_exp = len(vec_dist)/2
cfg = {'npoints': npoints_exp+100, 'trigger': DriveDataCaptureTrigger.PsoOutput}
cfg = {'ntotal': npoints_exp+100, 'trigger': DriveDataCaptureTrigger.PsoOutput}
ddc.configure(cfg)
ddc.stage()
npoints_rbv = ddc.nsamples_rbv.value
@@ -475,7 +475,7 @@ class AerotechAutomation1Test(unittest.TestCase):
# Configure DDC
npoints_exp = len(vec_dist)
cfg = {'npoints': npoints_exp+100, 'trigger': DriveDataCaptureTrigger.PsoOutput}
cfg = {'ntotal': npoints_exp+100, 'trigger': DriveDataCaptureTrigger.PsoOutput}
ddc.configure(cfg)
ddc.stage()
npoints_rbv = ddc.nsamples_rbv.value
@@ -548,7 +548,7 @@ class AerotechAutomation1Test(unittest.TestCase):
cfg = {'bounds': (acc_dist, 30 + acc_dist), 'wmode':"pulsed", "emode": 'Both'}
dev.configure(cfg)
# Configure the data capture (must be performed in start position)
cfg = {'npoints': 5*10, 'trigger': DriveDataCaptureTrigger.PsoOutput}
cfg = {'ntotal': 5*10, 'trigger': DriveDataCaptureTrigger.PsoOutput}
ddc.configure(cfg)
ddc.stage()
npoints_rbv = ddc.nsamples_rbv.value
@@ -575,7 +575,7 @@ class AerotechAutomation1Test(unittest.TestCase):
dev.configure(cfg)
dev.stage()
# Configure the data capture
cfg = {'npoints': 10, 'trigger': DriveDataCaptureTrigger.PsoOutput}
cfg = {'ntotal': 10, 'trigger': DriveDataCaptureTrigger.PsoOutput}
ddc.configure(cfg)
ddc.stage()
npoints_rbv = ddc.nsamples_rbv.value
@@ -643,7 +643,7 @@ class AerotechAutomation1Test(unittest.TestCase):
pso.configure(cfg)
# DDC setup (Tomcat runs in ENABLE mode, so only one posedge)
cfg = {'npoints': NumRepeat, 'trigger': DriveDataCaptureTrigger.PsoOutput}
cfg = {'ntotal': NumRepeat, 'trigger': DriveDataCaptureTrigger.PsoOutput}
ddc.configure(cfg)
print("\tStage")
@@ -713,7 +713,7 @@ class AerotechAutomation1Test(unittest.TestCase):
# Copy file to controller and run it
t_start = time()
dev.launch_script("tcatSequenceScan.ascript", task_index=4, filetext=text)
dev.launch_script("tcatSequenceScan.ascript", taskindex=4, filetext=text)
sleep(0.5)
dev.complete().wait()
t_end = time()