From 7e15ee282b1488cd292edb7fb9ab1900171f1921 Mon Sep 17 00:00:00 2001
From: Jessica McChesney <jmcchesn@anl.gov>
Date: Fri, 19 Aug 2022 09:37:11 -0500
Subject: [PATCH] debuggin scanRecord

---
 build/lib/iexcode/instruments/scanRecord.py | 50 ++++++++++++++++-----
 iexcode/instruments/scanRecord.py           | 44 +++++++++++++-----
 2 files changed, 72 insertions(+), 22 deletions(-)

diff --git a/build/lib/iexcode/instruments/scanRecord.py b/build/lib/iexcode/instruments/scanRecord.py
index 07ff5d0..32fc1cd 100644
--- a/build/lib/iexcode/instruments/scanRecord.py
+++ b/build/lib/iexcode/instruments/scanRecord.py
@@ -512,21 +512,30 @@ class ScanRecord:
     def check(self,scan_dim):
         """
         checks pvs connects and that positioners are within limits
+
+        returns scan_ok = True/False 
         """
-        self._check_pvs(scan_dim)
-        if not self._check_limits(scan_dim):
-            print("check positioner limits")
+        pv_ok = self._check_pvs(scan_dim)
+        limits_ok = self._check_limits(scan_dim)
+        
+        scan_ok = bool(pv_ok * limits_ok)
+        return scan_ok
 
-    def _check_pvs(self,scan_dim):
+    def _check_pvs(self,scan_dim,verbose=False):
         """
         Check if any of the detectors or positions pvs are not connected
 
+        returns connected = True/False
+
         Previously: Scan_Check
         """
-        print('Checking if all detectors & positioners are connected...')
-        scan_pv = self.ioc+"scan"+str(scan_dim)
+        if verbose:
+            print('Checking if all detectors & positioners are connected...')
 
+        scan_pv = self.ioc+"scan"+str(scan_dim)
+        
         #Detectors
+        det_ok = True
         for i in range(1,71):
             det_num=(str(i).zfill(2))
             det_pv=caget(scan_pv+".D"+det_num+"PV")
@@ -534,7 +543,10 @@ class ScanRecord:
                 det=PV(det_pv); time.sleep(0.1)#smallest sleep to allow for PV traffic
                 if not det.connected:
                     print("Detector "+det_num+" has a bad PV:  "+det.pvname+" not connected")
+                    det_ok = False
+
         #Positioners
+        pos_ok = True
         for i in range(1,5):
             pos_num=str(i)
             pos_pv=caget(scan_pv+".P"+pos_num+"PV")
@@ -542,8 +554,13 @@ class ScanRecord:
                 pos=PV(pos_pv)
                 if not pos.connected:
                     print("Positioner "+pos_num+" has a BAD PV:  "+pos.pvname+" not connected")
+                    pos_ok = False
+        if verbose:
+            print('Connected')
+        
+        return bool(pos_ok * det_ok)
 
-    def _check_limits(self,scan_dim):
+    def _check_limits(self,scan_dim,verbose=False):
         """
         checks if the scan parameters are within the limits
         returns limits_ok (True / False)
@@ -552,11 +569,16 @@ class ScanRecord:
         caput(scan_pv+'.CMND',1)
         time.sleep(.5)
         SMSG = caget(scan_pv+'.SMSG',as_string=True)
-        if len(SMSG) > 0:
+        if verbose:
+            print(SMSG)
+
+        if SMSG != 'SCAN Values within limits':
             print_warning_message('Positioner out of limits \n     '+SMSG)
             limits_ok = False
         else:
             limits_ok = True
+
+        return limits_ok
     
 
     ##############################################################################################################
@@ -658,7 +680,7 @@ class ScanRecord:
                 step  = caget(self.ioc+"scan"+str(i)+".P1SI")
                 print('Scan'+str(i)+': '+drive+'= '+str(start)+' / '+str(stop)+' / '+str(step))
         
-        if self._check_limits(scan_dim):
+        if self.check(scan_dim):
             filename = self.prefix(self.ioc)
             fileNum  = self.fileNum(self.ioc)
             print(filename+str(fileNum)+" started at ", dateandtime())
@@ -674,14 +696,20 @@ class ScanRecord:
     ##############################################################################################################
  
 
-    def empty_scan(self,**kwargs):
+    def empty_scan(self,npts=1,**kwargs):
         """
         starts a scan with out a drive
+        npts = number of points
+
+        **kwargs:
+            execute = True/False (default=True)
 
         Previously: Scan_Empty_Go
         """
         kwargs.setdefault('execute',True)
-        self.fillin("","",0,1,1,**kwargs)   
+        kwargs.setdefault('num_points',True)
+        self.fillin("","",0,npts,1,**kwargs)   
+        
         if kwargs['execute']:
             self.go(**kwargs)
  
diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py
index 30cf609..ce9ae01 100644
--- a/iexcode/instruments/scanRecord.py
+++ b/iexcode/instruments/scanRecord.py
@@ -512,21 +512,30 @@ class ScanRecord:
     def check(self,scan_dim):
         """
         checks pvs connects and that positioners are within limits
+
+        returns scan_ok = True/False 
         """
-        self._check_pvs(scan_dim)
-        if not self._check_limits(scan_dim):
-            print("check positioner limits")
+        pv_ok = self._check_pvs(scan_dim)
+        limits_ok = self._check_limits(scan_dim)
+        
+        scan_ok = bool(pv_ok * limits_ok)
+        return scan_ok
 
-    def _check_pvs(self,scan_dim):
+    def _check_pvs(self,scan_dim,verbose=False):
         """
         Check if any of the detectors or positions pvs are not connected
 
+        returns connected = True/False
+
         Previously: Scan_Check
         """
-        print('Checking if all detectors & positioners are connected...')
-        scan_pv = self.ioc+"scan"+str(scan_dim)
+        if verbose:
+            print('Checking if all detectors & positioners are connected...')
 
+        scan_pv = self.ioc+"scan"+str(scan_dim)
+        
         #Detectors
+        det_ok = True
         for i in range(1,71):
             det_num=(str(i).zfill(2))
             det_pv=caget(scan_pv+".D"+det_num+"PV")
@@ -534,7 +543,10 @@ class ScanRecord:
                 det=PV(det_pv); time.sleep(0.1)#smallest sleep to allow for PV traffic
                 if not det.connected:
                     print("Detector "+det_num+" has a bad PV:  "+det.pvname+" not connected")
+                    det_ok = False
+
         #Positioners
+        pos_ok = True
         for i in range(1,5):
             pos_num=str(i)
             pos_pv=caget(scan_pv+".P"+pos_num+"PV")
@@ -542,8 +554,13 @@ class ScanRecord:
                 pos=PV(pos_pv)
                 if not pos.connected:
                     print("Positioner "+pos_num+" has a BAD PV:  "+pos.pvname+" not connected")
+                    pos_ok = False
+        if verbose:
+            print('Connected')
+        
+        return bool(pos_ok * det_ok)
 
-    def _check_limits(self,scan_dim):
+    def _check_limits(self,scan_dim,verbose=False):
         """
         checks if the scan parameters are within the limits
         returns limits_ok (True / False)
@@ -552,11 +569,16 @@ class ScanRecord:
         caput(scan_pv+'.CMND',1)
         time.sleep(.5)
         SMSG = caget(scan_pv+'.SMSG',as_string=True)
-        if SMSG != 'SCAN Values within limits !!!!!':
+        if verbose:
+            print(SMSG)
+
+        if SMSG != 'SCAN Values within limits':
             print_warning_message('Positioner out of limits \n     '+SMSG)
             limits_ok = False
         else:
             limits_ok = True
+
+        return limits_ok
     
 
     ##############################################################################################################
@@ -658,7 +680,7 @@ class ScanRecord:
                 step  = caget(self.ioc+"scan"+str(i)+".P1SI")
                 print('Scan'+str(i)+': '+drive+'= '+str(start)+' / '+str(stop)+' / '+str(step))
         
-        if self._check_limits(scan_dim):
+        if self.check(scan_dim):
             filename = self.prefix(self.ioc)
             fileNum  = self.fileNum(self.ioc)
             print(filename+str(fileNum)+" started at ", dateandtime())
@@ -682,13 +704,13 @@ class ScanRecord:
         **kwargs:
             execute = True/False (default=True)
 
-
         Previously: Scan_Empty_Go
         """
         kwargs.setdefault('execute',True)
         kwargs.setdefault('num_points',True)
-        num_points
         self.fillin("","",0,npts,1,**kwargs)   
+        sleep(.1)
+        
         if kwargs['execute']:
             self.go(**kwargs)
  
-- 
GitLab