From b4fd945f8784a46d036b109b74a9d8ecb1fba197 Mon Sep 17 00:00:00 2001
From: jmcchesn <jmcchesn@aps.anl.gov>
Date: Mon, 26 Sep 2022 12:33:22 -0500
Subject: [PATCH] ID_scan_fillin updated to get rbv and val in correct order

---
 iexcode/instruments/IEX_VPU.py   | 16 +++++++---------
 iexcode/instruments/utilities.py |  6 +++++-
 iexcode/instruments/xrays.py     |  5 +++++
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/iexcode/instruments/IEX_VPU.py b/iexcode/instruments/IEX_VPU.py
index 9d6f049..9f850fd 100644
--- a/iexcode/instruments/IEX_VPU.py
+++ b/iexcode/instruments/IEX_VPU.py
@@ -413,9 +413,7 @@ def ID_set_eV(eV,verbose=True):
     """
     keV=eV/1000.0
     ID_set(keV,verbose=verbose)
-
-
-    
+   
 def ID_QP_ratio_get(verbose=True):
     """
     gets the read back for the QP ratio
@@ -524,17 +522,17 @@ def ID_scan_pvs():
     """
     val_pv=ID_pvs()['scan_val_eV']
     rbv_pv=""
-    return rbv_pv, val_pv
+    return val_pv, rbv_pv 
 
-def ID_scan_fillin(mda,scan_dim,start,stop,step,**kwargs):
+def ID_scan_fillin(start,stop,step,**kwargs):
     """
     fills in the scanRecord for scanning the ID set point
 
     **kwargs => scanRecord.fillin kwargs
     """
     #Setting up the ScanRecord for ID in Table mode
-    rbv_pv, val_pv  = ID_scan_pvs()
-    iex.BL.mda.fillin(scan_dim,rbv_pv,val_pv,start,stop,step,**kwargs)
+    val_pv, rbv_pv  = ID_scan_pvs()
+    iex.BL.mda.fillin(val_pv,rbv_pv,start,stop,step,**kwargs)
 
 
 def ID_scan_fillin_table(ID_array,**kwargs):
@@ -544,8 +542,8 @@ def ID_scan_fillin_table(ID_array,**kwargs):
     **kwargs => scanRecord.fillin kwargs
     """
     #Setting up the ScanRecord for ID in Table mode
-    rbv_pv, val_pv = ID_scan_pvs()
-    iex.BL.mda.fillin_table(rbv_pv,val_pv,ID_array,**kwargs)
+    val_pv, rbv_pv  = ID_scan_pvs()
+    iex.BL.mda.fillin_table(val_pv,rbv_pv,ID_array,**kwargs)
 
 ##############################################################################################################
 ##############################             ID direction table        ##############################
diff --git a/iexcode/instruments/utilities.py b/iexcode/instruments/utilities.py
index 7dd7914..da20726 100644
--- a/iexcode/instruments/utilities.py
+++ b/iexcode/instruments/utilities.py
@@ -138,7 +138,7 @@ def make_table(start_stop_step_lists):
     Previously: Scan_MakeTable           
     """
     table_array=np.array([])
-    if type(start_stop_step_lists) is not list:
+    if type(start_stop_step_lists[0]) is not list:
         start = start_stop_step_lists[0]
         stop = start_stop_step_lists[1]
         step = start_stop_step_lists[2]
@@ -148,9 +148,13 @@ def make_table(start_stop_step_lists):
             j+=step
     else:
         for i in range(0,len(start_stop_step_lists)):
+            if type(start_stop_step_lists[i]) != list:
+                print_warning_message("start_stop_step_lists must be a list of list")
             start=start_stop_step_lists[i][0]
             stop=start_stop_step_lists[i][1]
             step=start_stop_step_lists[i][2]
+            if stop <= start:
+                print_warning_message('start_stop_step_lists needs to be in assending order')
             j=start
             while j<=stop:
                 table_array=np.append(table_array, j)
diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py
index b809f10..6eb545e 100644
--- a/iexcode/instruments/xrays.py
+++ b/iexcode/instruments/xrays.py
@@ -415,6 +415,9 @@ def scanXAS(start_stop_step_lists,ID_eV=None,ID_tracking=False, **kwargs):
     
     #Setting up the ScanRecord for Mono and ID in Table mode
     mono_array,ID_array = BL_energy_tables(start_stop_step_lists,**kwargs)
+    #break is mono_array has no points
+    if len(list(mono_array)) == 0:
+        return
     kwargs.update({'positioner_num':1})
     mono_scan_table(mono_array,execute=False)
     if ID_tracking == True:
@@ -462,6 +465,8 @@ def BL_energy_tables(start_stop_step_lists,**kwargs):
     """
     kwargs.setdefault('QP_ratio', 100)
     mono_array = make_table(start_stop_step_lists)
+    if len(list(mono_array)) == 0:
+        print_warning_message('mono_array is length 0, check start_stop_step_lists')
     ID_array=np.array([])
     ID_mode,ID_QP_ratio,ID_sp,ID_rbv,hv,grt = energy_get_all(verbose=False)
     for hv_eV in mono_array:
-- 
GitLab