From 3ff28cfbe66650796aee9fd1dde6e80bed0ea9c0 Mon Sep 17 00:00:00 2001
From: "FR@29iduser" <rodolakis@anl.gov>
Date: Fri, 26 Aug 2022 15:31:16 -0500
Subject: [PATCH] shutters and valves debugged

---
 build/lib/iexcode/instruments/ARPES.py        | 108 +++----
 .../iexcode/instruments/IEX_endstations.py    |  49 ++--
 build/lib/iexcode/instruments/Kappa.py        | 271 +++++++-----------
 build/lib/iexcode/instruments/cameras.py      |  74 ++++-
 build/lib/iexcode/instruments/shutters.py     |  25 +-
 build/lib/iexcode/instruments/xrays.py        |  73 ++---
 iexcode.egg-info/PKG-INFO                     |   5 -
 iexcode.egg-info/SOURCES.txt                  |   2 +-
 iexcode/instruments/ARPES.py                  |  17 +-
 iexcode/instruments/IEX_endstations.py        |  15 +-
 iexcode/instruments/Kappa.py                  |  10 +-
 iexcode/instruments/cameras.py                |  11 +-
 iexcode/instruments/gate_valves.py            |  35 ---
 iexcode/instruments/shutters.py               |  25 +-
 iexcode/instruments/valves.py                 |  82 ++++++
 15 files changed, 441 insertions(+), 361 deletions(-)
 delete mode 100644 iexcode/instruments/gate_valves.py
 create mode 100644 iexcode/instruments/valves.py

diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py
index d54b041..90001dd 100644
--- a/build/lib/iexcode/instruments/ARPES.py
+++ b/build/lib/iexcode/instruments/ARPES.py
@@ -5,10 +5,12 @@ from epics import caget,caput,PV
 
 import iexcode.instruments.cfg as iex
 from iexcode.instruments.IEX_endstations import Endstation
+from iexcode.instruments.cameras import _enable_endstation_cameras
 
 from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda
+from iexcode.instruments.Logfile import Logfile
 from iexcode.instruments.staff import staff_detector_dictionary
-from iexcode.instruments.xrays import _xrays_detector_dictionary,_xrays_reset,xrays_get_all
+from iexcode.instruments.xrays import _xrays_detector_dictionary, _xrays_reset, xrays_get_all
 
 from iexcode.instruments.conversions_constants import *
 from iexcode.instruments.utilities import *
@@ -16,7 +18,7 @@ from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs
 
 from iexcode.instruments.Motors import Motors
 from iexcode.instruments.current_amplifiers import *
-from iexcode.instruments.gate_valves import valve_close, branch_valves
+from iexcode.instruments.valves import branch_valve_close
 from iexcode.instruments.shutters import branch_shutter_close
 
 #branch specific
@@ -26,9 +28,6 @@ from iexcode.instruments.Lakeshore_335 import Lakeshore_reset
 from iexcode.instruments.electron_analyzer import EA_init_Motors,folders_EA,EA
 
 default_ioc = '29idARPES:'
-#detector objects used with in module and returned by init
-global tey, ca15
-
 #############################################################################
 def ARPES_init(*userName,**kwargs):
     """
@@ -53,11 +52,13 @@ def ARPES_init(*userName,**kwargs):
     physical_motors = ['x','y','z','th','chi','phi']
     psuedo_motors = ['focus']
     global ARPES_Motors
-    ARPES_Motors = Motors('ARPES',ARPES_motor_dictionary(),physical_motors,psuedo_motors)
+    ARPES_Motors = Motors('ARPES',_ARPES_motor_dictionary(),physical_motors,psuedo_motors)
 
     #endstation
     iex.BL = Endstation('ARPES',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],ARPES_Motors)
-    
+    iex.BL.safe_state = ARPES_safe_state
+    iex.BL.endstation_get = ARPES_get_all
+
     #setting folders
     if kwargs['set_folders']:
         if iex.BL.mode == 'staff':
@@ -71,7 +72,7 @@ def ARPES_init(*userName,**kwargs):
         folders_ARPES(user_name,**kwargs)
 
         #update for default scanRecord advanced parameters
-        iex.BL.mda.log('ARPES',user_name,ARPES_log_header(),ARPES_log_entries)
+        iex.BL.mda.log=Logfile('ARPES',user_name,_ARPES_log_header(),_ARPES_log_entries)
 
     #EA
     if EA.connected: 
@@ -89,6 +90,9 @@ def ARPES_init(*userName,**kwargs):
     if kwargs['reset']:
         ARPES_reset(**kwargs)
     
+    #enable cameras
+    _enable_endstation_cameras()
+    
     print ('ARPES initalized')
     #return any detectors or other parameters that you want access to from jupyter
     return tey,ca15
@@ -96,7 +100,7 @@ def ARPES_init(*userName,**kwargs):
 ##############################################################################################################
 ##############################             ARPES detectors and motors         ##############################
 ##############################################################################################################
-def ARPES_detector_list():
+def _ARPES_detector_list():
     """
     list of detectors to trigger 
 
@@ -105,7 +109,7 @@ def ARPES_detector_list():
     ca_list=[["c",1],["b",15],["b",4],["b",13]]
     return ca_list
 
-def ARPES_detector_dictionary(xrays=True):
+def _ARPES_detector_dictionary():
     """
     returns a dictionary of the default detectors for the scan record
 
@@ -124,11 +128,12 @@ def ARPES_detector_dictionary(xrays=True):
        det_dict.update({17:EA._statsPlugin+"Total_RBV"})
 
     #add detectors related to beamline
-    if xrays: 
+    if iex.BL.xrays: 
         det_dict.update(_xrays_detector_dictionary())
+
     return det_dict
 
-def ARPES_motor_dictionary():
+def _ARPES_motor_dictionary():
     """
     returns a dictionary with  {name:[rbv,val,spmg,pv]}
     """
@@ -205,7 +210,7 @@ def folders_ARPES(user_name,**kwargs):
         else:
             print_warning_message("EA ioc is not running, h5 folder not set")
 
-def ARPES_reset(**kwargs):
+def ARPES_reset():
     """
     resets scanRecord, current amplifiers, mono limits and lakeshore
     """   
@@ -213,10 +218,11 @@ def ARPES_reset(**kwargs):
     if iex.BL.mode=='staff':
         iex.BL.mda.detector_dictionary = staff_detector_dictionary()
     else:
-        iex.BL.mda.detector_dictionary = ARPES_detector_dictionary(kwargs['xrays'])
-    iex.BL.mda.trigger_dictionary = ARPES_trigger_dictionary(**kwargs)
-    iex.BL.mda.scan_before_sequence = ARPES_scan_before_sequence(**kwargs)
-    iex.BL.mda.scan_after_sequence = ARPES_scan_after_sequence(**kwargs)
+        iex.BL.mda.detector_dictionary = _ARPES_detector_dictionary()
+    iex.BL.mda.trigger_dictionary = _ARPES_trigger_dictionary()
+    iex.BL.mda.scan_before_sequence = _ARPES_scan_before_sequence()
+    iex.BL.mda.scan_after_sequence = _ARPES_scan_after_sequence()
+    
     #resetting the scanRecord
     print("resetting the scanRecord - "+iex.BL.ioc)
     iex.BL.mda.reset_all()
@@ -229,8 +235,8 @@ def ARPES_reset(**kwargs):
         tey.reset()
 
     #resetting mono and other beamline stuff
-    if i_xrays_reset:
-        xrays_reset()
+    if iex.BL.xrays:
+        _xrays_reset()
 
     #reseting the ARPES Lakeshore
     pv = "29idARPES:LS335:"
@@ -253,15 +259,16 @@ def ARPES_get_all(verbose=True):
     vals={}
 
     #sample position
-    motor_dictionary = ARPES_motor_dictionary()
+    motor_dictionary = _ARPES_motor_dictionary()
     for motor in motor_dictionary.keys():
         vals[motor]=ARPES_Motors.get(motor,verbose=False)
         
-    #endstation pvs
+    #endstation/branch pvs
     extra_pvs = ARPES_extra_pvs()
     for key in extra_pvs.keys():
         vals.update(key,caget(extra_pvs[key]))
-    vals.update('exit_slit',slit3C_get())
+    if iex.BL.xrays:
+        vals.update('exit_slit',slit3C_get())
 
     #beamline info
     if iex.BL.xray:
@@ -269,8 +276,11 @@ def ARPES_get_all(verbose=True):
         vals.update(beamline_info) 
 
     if verbose:
+        print("-----------------------------------------------------------")   
         for key in vals:
             print(key+" = "+vals[key])
+        print("-----------------------------------------------------------")   
+
     return vals
 
 
@@ -278,14 +288,14 @@ def ARPES_get_all(verbose=True):
 ##############################################################################################################
 ##############################             logging           ##############################
 ##############################################################################################################
-def ARPES_log_header():
+def _ARPES_log_header():
     header_list={
         'EA': "scan,x,y,z,th,chi,phi,T,scan_mode,E1,E2,step,i,f,PE,lens_mode,SES slit #,hv,exit_slit,GRT,ID_SP,ID_RBV,ID_Mode,ID_QP,TEY1,TEY2,time,comment",
         'ARPES':"scan,motor,start,stop,step,x,y,z,th,chi,phi,T,hv,exit_slit,GRT,ID_SP,ID_RBV,ID_Mode,ID_QP,TEY_1,TEY_2,time,comment"
         }
     return header_list
 
-def ARPES_log_entries():
+def _ARPES_log_entries():
     """
     endstation info for log file
 
@@ -312,7 +322,7 @@ def ARPES_log_entries():
 ##############################################################################################################
 ##############################             ARPES scanRecord           ##############################
 ##############################################################################################################     
-def ARPES_scan_before_sequence(**kwargs):
+def _ARPES_scan_before_sequence(**kwargs):
     """
     writes the user string sequence to happen at the beginning of a scan
     returns before_scan_pv = pv for userStringSeq for before scan
@@ -334,7 +344,7 @@ def ARPES_scan_before_sequence(**kwargs):
     caput(before_scan_pv+".DESC","Before Scan")
 
     #sequence put CAs in passive
-    ca_list = ARPES_detector_list()
+    ca_list = _ARPES_detector_list()
     for (i,ca) in enumerate(ca_list):
         ca_pv = Keithley_pv(ca[0], ca[1])+':read.SCAN PP NMS'
         caput(before_scan_pv+".LNK" +str(i+1),ca_pv)
@@ -342,15 +352,15 @@ def ARPES_scan_before_sequence(**kwargs):
 
     return before_scan_proc
 
-def ARPES_ca_live_sequence(**kwargs):
+def _ARPES_ca_live_sequence(**kwargs):
     """
     """
     kwargs.setdefault('seq_num',7)
 
-    ca_live_sequence_proc = ca_live_sequence(iex.BL.ioc,kwargs['seq_num'],ARPES_detector_list())
+    ca_live_sequence_proc = ca_live_sequence(iex.BL.ioc,kwargs['seq_num'],_ARPES_detector_list())
     return ca_live_sequence_proc
 
-def ARPES_scan_after_sequence(**kwargs):
+def _ARPES_scan_after_sequence(**kwargs):
     """
     writes the user string sequence to happen at the end of a scan
     returns after_scan_pv = pv for userStringSeq for after scan
@@ -376,7 +386,7 @@ def ARPES_scan_after_sequence(**kwargs):
     caput(after_scan_pv+".DESC","After Scan")
         
     ## Put All relevant CA back in live mode
-    ca_live_sequence_proc = ARPES_ca_live_sequence(**kwargs)
+    ca_live_sequence_proc = _ARPES_ca_live_sequence(**kwargs)
     caput(after_scan_pv+".LNK1",ca_live_sequence_proc+" PP NMS")
     caput(after_scan_pv+".DO1",1)
 
@@ -401,7 +411,7 @@ def ARPES_scan_after_sequence(**kwargs):
     return after_scan_proc
 
 
-def ARPES_detector_triggers_sequence(**kwargs):    # do we need to add 29idb:ca5 ???
+def _ARPES_detector_triggers_sequence(**kwargs):    # do we need to add 29idb:ca5 ???
     """
     """
     kwargs.setdefault('seq_num',8)
@@ -414,7 +424,7 @@ def ARPES_detector_triggers_sequence(**kwargs):    # do we need to add 29idb:ca5
     userStringSeq_clear(scan_ioc,seq_num=kwargs['seq_num'])
     caput(detector_triggers_pv+".DESC","ARPES_Trigger1")
     
-    ca_list = ARPES_detector_list()
+    ca_list = _ARPES_detector_list()
     last = len(ca_list)
     for i,ca in enumerate(ca_list):
         ca_pv = Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS'
@@ -423,18 +433,18 @@ def ARPES_detector_triggers_sequence(**kwargs):    # do we need to add 29idb:ca5
 
     return detector_triggers_proc
 
-def ARPES_trigger_dictionary(**kwargs):
+def _ARPES_trigger_dictionary(**kwargs):
     """
     need to do something
     """
     trigger_dictionary = {
-        1:ARPES_detector_triggers_sequence(**kwargs),
+        1:_ARPES_detector_triggers_sequence(**kwargs),
     }
     return trigger_dictionary
 
 
 ##############################################################################################################
-##############################             ARPES Motor Scan Set Up        ##############################
+##############################             ARPES Motor Endcoders      ##############################
 ##############################################################################################################
 def ARPES_motor_encoder_sync():
     ioc = "29idc:"
@@ -474,7 +484,7 @@ def _ARPES_MoveSequence(destination):
         if the theta encoder stops reading the manipulator will CRASH!!!!
     """
     (x,y,z,th,chi,phi)=_ARPES_DefaultPosition(destination)
-    motor_dictionary = ARPES_motor_dictionary()
+    motor_dictionary = _ARPES_motor_dictionary()
     if x is None:
         print("Not a valid destination")
     else:
@@ -509,7 +519,7 @@ def _ARPES_limits_set(destination):
 
     Previously: ARPES_LimitsSet
     """
-    motor_dictionary = ARPES_motor_dictionary()
+    motor_dictionary = _ARPES_motor_dictionary()
     if destination == 'measure':
         (x,y,z,th,chi,phi)=_ARPES_DefaultPosition("measure")
         limits={'x':[5.5,-7],'y':[7,-5],'z':[-6,-310],'th':[th+35,th-25],'chi':[45,-15],'phi':[120,-120]}
@@ -534,7 +544,7 @@ def ARPES_transfer(chi=0,phi=0,**kwargs):
         EA_HV_Off=True; Turns off the EA HV
         Close_CBranch=True;  closes the C-shutter and the C-valve (main chamber to BL)
     """
-    ARPESgo2("transfer",**kwargs)
+    _ARPESgo2("transfer",**kwargs)
 
 def ARPES_measure(**kwargs):
     """
@@ -543,7 +553,7 @@ def ARPES_measure(**kwargs):
         chi=None # specify a value to move chi
         phi=None # specifiy a value to move phi
     """
-    ARPESgo2("measure",**kwargs)
+    _ARPESgo2("measure",**kwargs)
 
 def ARPES_LEED(**kwargs):
     """
@@ -555,9 +565,9 @@ def ARPES_LEED(**kwargs):
         chi=None # specify a value to move chi
         phi=None # specifiy a value to move phi
     """
-    ARPESgo2("LEED",**kwargs)    
+    _ARPESgo2("LEED",**kwargs)    
 ####################################################################################################
-def ARPESgo2(destination,**kwargs):
+def _ARPESgo2(destination,**kwargs):
     """
     Moves the ARPES manipulator to the default position: 
     destination: "transfer", "measure", "LEED"
@@ -585,7 +595,7 @@ def ARPESgo2(destination,**kwargs):
     #Move x,y,z,th
     _ARPES_MoveSequence(destination)
     #Move chi and phi back to 0
-    motor_dictionary = ARPES_motor_dictionary()
+    motor_dictionary = _ARPES_motor_dictionary()
     if kwargs["chi"] is not None:
         caput(motor_dictionary['chi'][1],kwargs["chi"])
     if kwargs["phi"] is not None:
@@ -595,7 +605,7 @@ def ARPESgo2(destination,**kwargs):
 ##############################################################################################################
 ##############################             ARPES pvs for GUIs (caQtDM)        ##############################
 ##############################################################################################################
-def ARPES_StringCalc_trigger2_active():
+def _ARPES_StringCalc_trigger2_active():
     """
     setup a string calc to be used by caQtDM to indicate that the trigger 2 is filled
     """
@@ -627,16 +637,18 @@ def ARPES_safe_state(**kwargs):
     global EA
     
     if kwargs["EA_off"]:
-        try:
+        if EA.connected: 
             EA.off(quiet=False)
-        except:
+        else:
             print('EA is not running, visually confirm HV is off')
+    
+    if kwargs['shutter_close']:
+        branch_shutter_close()
 
     if kwargs['valve_close']:
-       valve_close(branch_valves('c'), verbose=True)
+       branch_valve_close()
+
 
-    if kwargs['shutter_close']:
-        branch_shutter_close('c')
 
 ##############################################################################################################
 ##############################              ARPES motors       ##############################
diff --git a/build/lib/iexcode/instruments/IEX_endstations.py b/build/lib/iexcode/instruments/IEX_endstations.py
index b24b05b..d937acd 100644
--- a/build/lib/iexcode/instruments/IEX_endstations.py
+++ b/build/lib/iexcode/instruments/IEX_endstations.py
@@ -1,11 +1,5 @@
-from math import floor
-from re import M
-import time
-from tkinter.messagebox import NO
-
-from epics import caput
-
 from iexcode.instruments.scanRecord import ScanRecord
+from iexcode.instruments.utilities import print_warning_message
 
 import iexcode.instruments.cfg as iex
 
@@ -41,7 +35,7 @@ class Endstation:
 
     """
 
-    def __init__(self,endstation_name,scan_ioc,xrays,BL_mode,Motors=None):
+    def __init__(self,endstation_name,scan_ioc,xrays,BL_mode,Motors=None,**kwargs):
         """
         intializes the several beamline variables 
 
@@ -49,18 +43,22 @@ class Endstation:
         
         BL = Endstation()
             BL.endstation => endstation_name
+            BL.branch => BL branch 'c' or 'd' only (used for shutter checks)
             BL.xrays => True/False 
             BL.mode => 'user'/'staff' previously: BL_Mode_Set
             BL.folder => 'b','c','d'
             BL.prefix => 'ARPES_','Kappa_'
             BL.ioc => previously: BL_ioc()
             BL.Motors => motor calls
+            BL.safe_state => function to put endstation in a 'safe state'
+            BL.endstation_get => function to return endstation status
 
-            intialization does not set default detectors and logging for .mda
+            Note intialization does not set default detectors and logging for .mda
             
         """
        
         self.endstation = None
+        self.branch = None
         self.ioc = scan_ioc
         self.folder = None
         self.prefix = None
@@ -71,7 +69,8 @@ class Endstation:
         self.mda = ScanRecord(scan_ioc)
         self.Motors = Motors
 
-        #global BL here
+        self.safe_state = None
+        self.endstation_get = None
         
         BL_mode_list = ['user','staff']
 
@@ -91,11 +90,14 @@ class Endstation:
                 if endstation_name == 'ARPES':
                     self.folder = 'c'
                     self.prefix = 'ARPES_'
+                    self.branch = 'c'
                 elif endstation_name == 'Kappa':
                     self.folder = 'd'
                     self.prefix = 'Kappa_'
+                    self.branch = 'd'
                 #elif endstation_name == 'Octupole':
                     #self.folder = 'e'
+                    self.branch = 'd'
                 else:
                     print('folder and prefix not set')
 
@@ -104,29 +106,37 @@ class Endstation:
                 self.folder = 'b' 
                 self.prefix = endstation_name+"_"
         else:
-            print('Not a valid BL_mode choice')
-            print('BL_modes: '+BL_mode_list) 
+            message = 'Not a valid BL_mode choice\n'
+            message += 'BL_modes: '+BL_mode_list
+            print_warning_message(message)
             return  
 
-    def set_logfile_path():
-        """
-        sets the default logfile path
-        """
+        if 'safe_state' in kwargs:
+            self.safe_state = kwargs['safe_state']
+        if 'endstation_get' in kwargs:
+            self.endstation_get = kwargs['endstation_get']
+
 
 ##############################################################################################################
 ##############################               BL commands            ##############################
 ##############################################################################################################
 def BL_ioc():
     """
-    returns the branch from the Endstation instance
+    returns the ioc from the Endstation instance
     """
     return iex.BL.ioc
 
+def BL_branch():
+    """
+    returns the branch from the Endstation instance
+    """
+    return iex.BL.branch
+
 def BL_mode():
     """
     returns the beamline mode, User / Staff / No_Xray
     """
-    return iex.BL.ioc
+    return iex.BL.mode
 
 def BL_mda_prefix():
     """
@@ -139,3 +149,6 @@ def BL_mda_filepath():
     returns the mda file prefix
     """
     return iex.BL.filepath
+
+##############################################################################################################
+
diff --git a/build/lib/iexcode/instruments/Kappa.py b/build/lib/iexcode/instruments/Kappa.py
index 0f40c56..edd6198 100644
--- a/build/lib/iexcode/instruments/Kappa.py
+++ b/build/lib/iexcode/instruments/Kappa.py
@@ -6,14 +6,12 @@ from epics import caget, caput,PV
 
 import iexcode.instruments.cfg as iex
 from iexcode.instruments.IEX_endstations import Endstation
-
-iex.BL = Endstation(endstation_name,scan_ioc,xrays,BL_mode,Motors=None)
-
+from iexcode.instruments.cameras import _enable_endstation_cameras
 
 from iexcode.instruments.staff import staff_detector_dictionary
 from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda
 from iexcode.instruments.staff import staff_detector_dictionary
-from iexcode.instruments.xrays import xrays_detector_dictionary,xrays_reset,xrays_get_all
+from iexcode.instruments.xrays import _xrays_detector_dictionary,_xrays_reset,xrays_get_all
 
 from iexcode.instruments.conversions_constants import *
 from iexcode.instruments.utilities import *
@@ -21,7 +19,7 @@ from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs
 
 from iexcode.instruments.Motors import Motors
 from iexcode.instruments.current_amplifiers import SRS, ca_reset_all, Keithley_pv
-from iexcode.instruments.gate_valves import valve_close, branch_valves
+from iexcode.instruments.valves import branch_valve_close
 from iexcode.instruments.shutters import branch_shutter_close
 
 #branch specific
@@ -33,14 +31,11 @@ from iexcode.instruments.MPA import MPA
 from iexcode.instruments.spec_stuff import folders_spec
 
 default_ioc = '29idKappa:'
-
-global tey, d3, d4, mesh, tthdet
-
 #############################################################################
 def Kappa_init(*userName,**kwargs):
     """
     used to intialize the Endstation class which carries scanRecord, logging ... parameters
-    returns global detectors relavent to this endstation (tey,ca15)
+    returns global detectors relavent to this endstation (tey,d3,d4,mesh,Kappa_scaler_pv,tth_pv,tthdet)
 
         *userName is an optional parameter, will be prompted if set_folders=True
 
@@ -59,49 +54,52 @@ def Kappa_init(*userName,**kwargs):
     #motors
     physical_motors = ['x','y','z','tth','kth','kap','kphi']
     psuedo_motors = ['th','chi','phi']
-    Kappa_Motors = Motors('Kappa',Kappa_motor_dictionary(),physical_motors,psuedo_motors)
+    global Kappa_Motors
+    Kappa_Motors = Motors('Kappa',_Kappa_motor_dictionary(),physical_motors,psuedo_motors)
 
     #endstation
-    iex.BL = Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],ARPES_Motors)
-
-    #scan
-    if kwargs['BL_mode']=='staff':
-        detector_dictionary = staff_detector_dictionary()
-    else:
-        detector_dictionary = Kappa_detector_dictionary()
+    iex.BL = Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],Kappa_Motors)
 
-    mda_scanRecord = ScanRecord(kwargs['scan_ioc'],detector_dictionary,
-    Kappa_trigger_dictionary(scan_ioc,scan_dim,),Kappa_scan_before_sequence(scan_ioc,scan_dim),Kappa_scan_after_sequence(scan_ioc,scan_dim))
+    #setting folders
+    if kwargs['set_folders']:
+        if iex.BL.mode == 'staff':
+            user_name = 'staff'
+        else:
+            if len(userName)==0:
+                user_name = input('user name: ')
+            else:
+                user_name = userName[0]
+        print(user_name)
+        folders_Kappa(user_name,**kwargs)
 
-    
+        #update for default scanRecord advanced parameters
+        iex.BL.mda.log('Kappa',user_name,_Kappa_log_header(),_Kappa_log_entries)
 
     #global detectors
+    global tey,d3,d4,mesh,Kappa_scaler_pv,tth_pv,tthdet
     tey = SRS("29idMZ0:scaler1.S2", '29idd:A1')
     d3 = SRS("29idMZ0:scaler1.S3", '29idd:A2')
     d4 = SRS("29idMZ0:scaler1.S4", '29idd:A3')
     mesh = SRS("29idMZ0:scaler1.S14", '29idd:A4')
     Kappa_scaler_pv = '29idMZ0:scaler1.CNT'
-    tth_pv = Kappa_motor_dictionary('tth')[3]
+    tth_pv = _Kappa_motor_dictionary('tth')[3]
     iex.mpa = MPA()
     tthdet = Kappa_Detector(Kappa_Motors)
-
-    #setting folders
-    if 'set_folders':
-        if iex.BL.mode == 'staff':
-            user_name = 'staff'
-        else:
-            user_name = input('user name: ')
-        folders_Kappa(user_name,**kwargs)
     
-    #resetting
-    if 'reset':
-        Kappa_reset()
+    #resetting everything
+    if kwargs['reset']:
+        Kappa_reset(**kwargs)
 
+    #enable cameras
+    _enable_endstation_cameras()
 
+    print ('Kappa initalized')
+    #return any detectors or other parameters that you want access to from jupyter
+    return tey,d3,d4,mesh,Kappa_scaler_pv,tth_pv,tthdet
 ##############################################################################################################
 ##############################                    detectors and motors                ##############################
 ##############################################################################################################
-def Kappa_detector_list():
+def _Kappa_detector_list():
     """
     list of detectors to trigger 
 
@@ -111,7 +109,7 @@ def Kappa_detector_list():
     return ca_list
 
 
-def Kappa_detector_dictionary(**kwargs):
+def _Kappa_detector_dictionary(**kwargs):
     """
     returns a dictionary of the default detectors
 
@@ -177,10 +175,14 @@ def Kappa_detector_dictionary(**kwargs):
     if kwargs['add_vortex']:
         det_dict.update(vortex)
 
+    #add detectors related to beamline
+    if iex.BL.xrays: 
+        det_dict.update(_xrays_detector_dictionary())
+
     return det_dict
 
 
-def Kappa_motor_dictionary(name):
+def _Kappa_motor_dictionary(name):
     """
     motor_dictionary = {name:[rbv,val,spmg,pv]} for physical and psuedo/Euler motors
     usage:
@@ -283,8 +285,18 @@ def Kappa_reset():
     """
     resets scanRecord, current amplifiers, mono limits and lakeshore
     """
+    #writing default parameters to iex.BL.mda
+    if iex.BL.mode=='staff':
+        iex.BL.mda.detector_dictionary = staff_detector_dictionary()
+    else:
+         iex.BL.mda.detector_dictionary = _Kappa_detector_dictionary()
+    iex.BL.mda.trigger_dictionary = _Kappa_trigger_dictionary()
+    iex.BL.mda.scan_before_sequence = _Kappa_scan_before_sequence()
+    iex.BL.mda.scan_after_sequence = _Kappa_scan_after_sequence()    
+    
     #resetting the scanRecord
-    iex.BL.mda.reset()
+    print("resetting the scanRecord - "+iex.BL.ioc)
+    iex.BL.mda.reset_all()
 
     #resetting the current amplifiers
     if iex.BL.xray:
@@ -292,26 +304,17 @@ def Kappa_reset():
     
     #resetting mono and anyother beamline stuff
     if iex.BL.xrays:
-        xrays_reset()
+        _xrays_reset()
 
-    #reseting the Kappa Lakeshore
+    #resetting mono and other beamline stuff
+    if iex.BL.xrays:
+        _xrays_reset()
 
     #motors home and sync
-    SmarAct_motors_home()
-    PI_motors_sync()
+    _SmarAct_motors_home()
+    _PI_motors_sync()
     Euler_motors_sync()
 
-def Kappa_reminder_list(ioc):
-    """
-    resets scanRecord, current amplifiers, mono limits  and synchs motors
-    """
-    iex.BL.mda.reset()
-    if iex.BL.xray:
-        ca_reset_all()
-
-
-
-
 
 ##############################################################################################################
 ##############################                    get all                 ##############################
@@ -323,32 +326,36 @@ def Kappa_get_all(verbose=True):
     vals = {}
 
     #sample postion
-    motor_dictionary = Kappa_motor_dictionary()
+    motor_dictionary = _Kappa_motor_dictionary()
     for motor in motor_dictionary.keys():
         vals[motor]=Kappa_Motors.get(motor,verbose=False)
 
-    #endstation pvs
+    #endstation/branch pvs
     extra_pvs = Kappa_extra_pvs()
     for key in extra_pvs.keys():
         vals.update(key,caget(extra_pvs[key]))
+    if iex.BL.xrays:
+        vals.update('exit_slit',slit3D_get())
 
     #beamline info
     if iex.BL.xray:
         beamline_info = xrays_get_all()
-        #vals.update(beamline_info) 
+        vals.update(beamline_info) 
 
     mesh.get()
     vals.update({'mesh':mesh.current})
 
     if verbose:
+        print("-----------------------------------------------------------")   
         for key in vals:
             print(key+" = "+vals[key])
+        print("-----------------------------------------------------------")   
     return vals
 
 ##############################################################################################################
 ##############################                         logging                  ##############################
 ##############################################################################################################
-def Kappa_log_header():
+def _Kappa_log_header():
     """
     header for the log file
     """
@@ -357,7 +364,7 @@ def Kappa_log_header():
     header_list = {'Kappa':h}
     return header_list 
 
-def Kappa_log_entries():
+def _Kappa_log_entries():
     """
     enstation info for log file
 
@@ -390,7 +397,7 @@ def Kappa_log_entries():
 ##############################################################################################################
 ##############################             Kappa scanRecord           ##############################
 ##############################################################################################################
-def Kappa_scan_before_sequence(scan_ioc,scan_dim,**kwargs):
+def _Kappa_scan_before_sequence(scan_ioc,scan_dim,**kwargs):
     """
     writes the user string sequence to happen at the beginning of a scan
     returns before_scan_pv = pv for userStringSeq for before scan
@@ -417,7 +424,7 @@ def Kappa_scan_before_sequence(scan_ioc,scan_dim,**kwargs):
 
     return before_scan_proc
 
-def Kappa_scan_after_sequence(scan_ioc,scan_dim,**kwargs):
+def _Kappa_scan_after_sequence(scan_ioc,scan_dim,**kwargs):
     """
     writes the user string sequence to happen at the end of a scan
     returns after_scan_pv = pv for userStringSeq for after scan
@@ -467,7 +474,7 @@ def Kappa_scan_after_sequence(scan_ioc,scan_dim,**kwargs):
 
     return after_scan_proc
 
-def Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs):    # do we need to add 29idb:ca5 ???
+def _Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs):    # do we need to add 29idb:ca5 ???
     """
     """
     kwargs.setdefault(seq_num,8)
@@ -484,7 +491,7 @@ def Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs):    # do we nee
     caput(detector_triggers_pv+".LNK" +str(1),scaler_pv)
     caput(detector_triggers_pv+".WAIT"+str(1),"After"+str(last))
     
-    ca_list = Kappa_detector_list()
+    ca_list = _Kappa_detector_list()
     last = len(ca_list)
     for i,ca in enumerate(ca_list):
         ca_pv = Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS'
@@ -493,12 +500,12 @@ def Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs):    # do we nee
 
     return detector_triggers_proc
 
-def Kappa_trigger_dictionary(scan_ioc,scan_dim,**kwargs):
+def _Kappa_trigger_dictionary(scan_ioc,scan_dim,**kwargs):
     """
     need to do something
     """
     trigger_dictionary = {
-        1:Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs),
+        1:_Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs),
     }
     return trigger_dictionary
 
@@ -509,7 +516,6 @@ def Kappa_trigger_dictionary(scan_ioc,scan_dim,**kwargs):
 ##############################        Kappa  Motor Scan Set Up        ##############################
 ##############################################################################################################
 
-
 def Kappa_sample_Euler_list():
     """
     returns list of motor names used by mvsample
@@ -517,7 +523,6 @@ def Kappa_sample_Euler_list():
     motor_list = ['th','chi','phi']
     return motor_list
 
-
 def Kappa_4c_mprint():
     """
     returns the dictionary of the current sample position in 4c units 
@@ -529,7 +534,7 @@ def Kappa_4c_mprint():
     positions={}
     motors=Kappa_sample_Euler_list()
     for motor in motors:
-        positions.update(motor,Kappa_motor_dictionary()(motor)[0])
+        positions.update(motor,_Kappa_motor_dictionary()(motor)[0])
     return positions
 
 def Kappa_4c_move(th_chi_phi_list):
@@ -544,48 +549,46 @@ def Kappa_4c_move(th_chi_phi_list):
     for motor,i in enumerate(motor_list):
         Kappa_Motors.get(motor,verbose=True)
 
-   
-
-def SmarAct_motor_list():
+def _SmarAct_motor_list():
     """
     returns a list of the motor names for the SmarAct motors in the Kappa
     """
     return ['x','y','z']
 
-def SmarAct_motors_home():
+def _SmarAct_motors_home():
     """
     Homes the piezo (x,y,z). Home position is middle of travel
 
     Previously: Home_SmarAct_Motor
     """
-    motor_dictionary = Kappa_motor_dictionary()
-    for motor in SmarAct_motor_list():
+    motor_dictionary = _Kappa_motor_dictionary()
+    for motor in _SmarAct_motor_list():
         pv = motor_dictionary[motor][3]
         caput(pv+'.HOMF',1)
         sleep(10)
     print('SamrAct motors VAL homed')
 
-def SmarAct_enable():
-    motor_dictionary = Kappa_motor_dictionary()
-    for motor in SmarAct_motor_list():
+def _SmarAct_enable():
+    motor_dictionary = _Kappa_motor_dictionary()
+    for motor in _SmarAct_motor_list():
         spmg = motor_dictionary[motor][2]
         caput(spmg,3)  # 3=Go
 
-def SmarAct_disable():
-    motor_dictionary = Kappa_motor_dictionary()
-    for motor in SmarAct_motor_list():
+def _SmarAct_disable():
+    motor_dictionary = _Kappa_motor_dictionary()
+    for motor in _SmarAct_motor_list():
         spmg = motor_dictionary[motor][2]
         caput(spmg,0)  # 1=Stop
 
-def PI_motor_list():
+def _PI_motor_list():
     """
     returns a list of the motor names for the SmarAct motors in the Kappa
     """
     return ['kap','kth','tth']
 
-def PI_motors_sync():
-    motor_dictionary = Kappa_motor_dictionary()
-    for motor in PI_motor_list():
+def _PI_motors_sync():
+    motor_dictionary = _Kappa_motor_dictionary()
+    for motor in _PI_motor_list():
         val_pv = motor_dictionary[motor][1]
         rbv_pv = motor_dictionary[motor][0]
         current_rbv=caget(rbv_pv)
@@ -608,7 +611,7 @@ def Kappa_kphi_reset_zero(val):
     resets the zero for the kphi motor
 
     """
-    kphi_pv = Kappa_motor_dictionary()['kphi'][3]
+    kphi_pv = _Kappa_motor_dictionary()['kphi'][3]
     caput(kphi_pv+".SET",1)    # 1 = Set
     sleep(0.5)
     caput("kphi_pv.VAL",val)
@@ -622,9 +625,7 @@ def Kappa_tth_reset_zero():
     """
     tthdet.tth0_set()
 
-
-
-def Kappa_th2th_scan_sensitivity(th_table,gain_num_table,gain_unit_table,**kwargs):
+def th2th_scan_sensitivity(th_table,gain_num_table,gain_unit_table,**kwargs):
     """
     Scans th2th with variable gain on SRS# (srs_num).
     Gain is specified for a given th2th range by building tables as follow:
@@ -665,7 +666,7 @@ def Kappa_th2th_scan_sensitivity(th_table,gain_num_table,gain_unit_table,**kwarg
 
     kth_offset = Kappa_kth_offset_get()
 
-    motor_dictionary = Kappa_motor_dictionary()
+    motor_dictionary = _Kappa_motor_dictionary()
     kth_val,kth_rbv,kth_spmg,kth_pv = motor_dictionary['kth']
     tth_val,tth_rbv,tth_spmg,tth_pv = motor_dictionary['tth']
 
@@ -699,7 +700,7 @@ def Kappa_th2th_scan_sensitivity(th_table,gain_num_table,gain_unit_table,**kwarg
         iex.BL.mda.table_reset_after(**kwargs)
         scaler_cts(verbose=False)
 
-def Kappa_scan_th2th(tth_start,tth_stop,tth_step,th_offset,**kwargs):
+def scan_th2th(tth_start,tth_stop,tth_step,th_offset,**kwargs):
     """
     Used for a linear (not table) scan where th =  tth /2 + th_offset
     **kwargs
@@ -721,8 +722,8 @@ def Kappa_scan_th2th(tth_start,tth_stop,tth_step,th_offset,**kwargs):
     print('th: '+str(th_start)+"/"+str(th_stop)+"/"+str(tth_step/2.0))
     
     #write to the scanRecord
-    th_val,th_rbv,th_spmg,th_pv = Kappa_motor_dictionary['th']
-    tth_val,tth_rbv,tth_spmg,tth_pv = Kappa_motor_dictionary['tth']
+    th_val,th_rbv,th_spmg,th_pv = _Kappa_motor_dictionary['th']
+    tth_val,tth_rbv,tth_spmg,tth_pv = _Kappa_motor_dictionary['tth']
 
     kwargs.update("positioner_num",2)
     iex.BL.mda.fillin(th_val,th_rbv,th_start,th_stop,th_step,**kwargs)
@@ -738,7 +739,7 @@ def Kappa_scan_th2th(tth_start,tth_stop,tth_step,th_offset,**kwargs):
         scaler_cts(verbose=False)
 
 
-def scan_th2th_table(tth_table,th0,**kwargs):
+def th2th_table(tth_table,th0,**kwargs):
     """
     Create a table for tth, e.g.:
         mytable_tth=[]
@@ -763,8 +764,8 @@ def scan_th2th_table(tth_table,th0,**kwargs):
     tth_table=np.asarray(tth_table)
     th_table=tth_table/2.0+th0
 
-    th_val,th_rbv,th_spmg,th_pv = Kappa_motor_dictionary['th']
-    tth_val,tth_rbv,tth_spmg,tth_pv = Kappa_motor_dictionary['tth']
+    th_val,th_rbv,th_spmg,th_pv = _Kappa_motor_dictionary['th']
+    tth_val,tth_rbv,tth_spmg,tth_pv = _Kappa_motor_dictionary['tth']
 
     #write to the scanRecord
     kwargs.update("positioner_num",1)
@@ -790,22 +791,22 @@ def scan_th2th_table(tth_table,th0,**kwargs):
 #############################################################################################################
 ##############################             Preset Positions        ##############################
 ##############################################################################################################
-def KappaTransfer_StrSeq():
+def _KappaTransfer_StrSeq():
     #User= [    DESC,        x,        y,      z,        tth,       kth,       kap,    kphi]
     User = ["Kappa Transfer",0, -2650, -650, 0, 57, 0, -88]
     n=4
-    KappaPreset_StrSeq(n,User)
+    _KappaPreset_StrSeq(n,User)
 
 
-def KappaGrazing_StrSeq(): #Need to determine positions and then add to the Kappa graphic
+def _KappaGrazing_StrSeq(): #Need to determine positions and then add to the Kappa graphic
     #Dial= [    DESC,        x,        y,      z,        tth,       kth,       kap,    kphi]
     User = ["Kappa Grazing",0, 0, 0, 0, 57.045, 134.76,57.045]
     n=3
-    KappaPreset_StrSeq(n,User)
+    _KappaPreset_StrSeq(n,User)
 
 def Kappa_ResetPreset():
-    KappaGrazing_StrSeq()
-    KappaTransfer_StrSeq()
+    _KappaGrazing_StrSeq()
+    _KappaTransfer_StrSeq()
 
 
 
@@ -832,72 +833,6 @@ def Kappa_light(ON_OFF):
     print(("Turning light "+ON_OFF+"."))
 
 
-
-
-def Kappa_detector_triggers_strSeq(**kwargs):    # do we need to add 29idb:ca5 ???
-    """
-    """
-    kwargs.setdefault(seq_num,8)
-    seq_num=kwargs['seq_num']
-    
-    detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(iex.BL.ioc, seq_num)
-       
-    #clear the userStringSeq
-    userStringSeq_clear(iex.BL.ioc,seq_num=kwargs['seq_num'])
-    caput(detector_triggers_pv+".DESC","Kappa_Trigger1")
-
-    #no triggers see ARPES_detector_triggers_sequence for example
-
-    return detector_triggers_proc
-
-
-
-
-
-
-def KappaPreset_StrSeq(n,User):
-    scanIOC="Kappa"
-    motorIOC="29idKappa:"
-    motor = ["m2","m3","m4","m9","m8","m7","m1"]
-    strSeq_pv = userStringSeq_clear(iex.BL.mda,n)
-
-    if User[0] == "Kappa Grazing":  phi0= 0
-    if User[0] == "Kappa Transfer": phi0= 57
-    caput(strSeq_pv+".DESC",User[0])
-    caput(strSeq_pv+".LNK1", "29idKappa:userCalcOut9.A CA NMS")       # MPA HV pV
-    caput(strSeq_pv+".DO1",0)                                       # MPA HV = 0
-    caput(strSeq_pv+".WAIT1","Wait")                                # Wait for completion
-    caput(strSeq_pv+".LNK2", "29idKappa:m1.VAL CA NMS")               # phi = phi0
-    caput(strSeq_pv+".DO2",phi0)                                       
-    caput(strSeq_pv+".WAIT2","Wait")                                # Wait for completion
-    for i in range(3,10):
-        caput(strSeq_pv+".LNK"+str(i),motorIOC+motor[i-3]+".VAL CA NMS")
-        caput(strSeq_pv+".DO"+str(i),User[i-2])
-        if i < 9:
-            caput(strSeq_pv+".WAIT"+str(i),"After8")
-
-
-
-
-    
- 
-    
-    
-def Bragg_Angle_CalcOut(d,eV,l):
-    n=7
-    userCalcOut_pv = userCalcOut_clear(iex.BL.mda,n)
-
-    h=4.135667516e-15
-    c=299792458
-    f=h*c*1e9*10
-    caput(userCalcOut_pv+"DESC","Bragg_Angle")
-    caput(userCalcOut_pv+"A",d)
-    caput(userCalcOut_pv+"B",l)
-    caput(userCalcOut_pv+"C",eV)
-    caput(userCalcOut_pv+"D",np.pi)
-    caput(userCalcOut_pv+"E",f)
-    caput(userCalcOut_pv+".CALC$","ASIN(B*E/(C*"+str(2)+"*A))*"+str(180)+"/D")
-
 ##############################################################################################################
 ########################        Scan Temp and Pressure           ##############################
 ##############################################################################################################
@@ -941,9 +876,11 @@ def Kappa_safe_state(**kwargs):
         except:
             print('MPA is not running')
 
+    if kwargs['shutter_close']:
+        branch_shutter_close()
+    
     if kwargs['valve_close']:
-       valve_close(branch_valves('d'), verbose=True)
+       branch_valve_close()
+
 
-    if kwargs['shutter_close']:
-        branch_shutter_close('d')
     
\ No newline at end of file
diff --git a/build/lib/iexcode/instruments/cameras.py b/build/lib/iexcode/instruments/cameras.py
index 3cfb114..e91f8d3 100644
--- a/build/lib/iexcode/instruments/cameras.py
+++ b/build/lib/iexcode/instruments/cameras.py
@@ -1,11 +1,15 @@
 
-from epics import caget, caput
+import time 
+from epics import caget,caput,PV
 
-from iexcode.instruments.userCalcs import userStringSeq_clear
+import iexcode.instruments.cfg as iex
 from iexcode.instruments.AD_utilities import *
-from iexcode.instruments.IEX_endstations import *
 
-def cam_pv_dictionary(cam_num):
+##############################################################################################################
+##############################              Camera PV dictionary            ##############################
+##############################################################################################################
+
+def _pv_dictionary():
     """
     dictionary of pv names for the beamline cameras
     """
@@ -17,14 +21,45 @@ def cam_pv_dictionary(cam_num):
         5:"29idarv5:",
         6:"29id_ps6:",
     }
-    return d[cam_num]
+    return d
 
-def cam_scan_setup(cam_num,ADtype='TIFF',**kwargs):
+##############################################################################################################
+##############################             Endstation Cameras           ##############################
+##############################################################################################################
+   
+def _enable_endstation_cameras(unused_off=True):
     """
-    sets up the BL scanRecord to trigger the camera (trigger - 2)
+    Turns on cameras related to a given endstation if they are connected
+    unused_off=True turns off other cameras
+
     """
-    ADplugin = cam_pv_dictionary(cam_num)+ADtype+":"
-    ADplugin_ScanSetup(ADplugin,BL.mda, **kwargs)  
+    endstation=iex.BL.endstation
+
+    #For new endstation modify here:
+    cam_dict={'ARPES':[0,1,2],'Kappa':[3,4,6]}  # index of cam_list 
+
+    d=_pv_dictionary()
+    for num in d.keys(): 
+        pv=d[num]+"cam1:Acquire"   
+        #camera in list
+        if num in cam_dict[endstation]:
+            #two connected to deal with network traffic
+            PV(pv).connected
+            time.sleep(0.1)
+            if PV(pv).connected:  
+                caput(pv,'Acquire')
+            else:
+                print(d[num]+" ioc in not running")
+        #camera not in list
+        else:
+            if unused_off:
+                if PV(pv).connected:  
+                    caput(pv,'Done')
+
+
+##############################################################################################################
+##############################             Camera Snapping an image         ##############################
+##############################################################################################################
 
 def cam_snap(cam_num,ADtype='TIFF',**kwargs):
     """
@@ -37,15 +72,28 @@ def cam_snap(cam_num,ADtype='TIFF',**kwargs):
                 False => leave saving enabled and camera in single acquision
 
     """
-    ADplugin = cam_pv_dictionary(cam_num)+ADtype+":"
-    AD_SaveFileSetup(ADplugin,BL.mda,**kwargs)
+    ADplugin = _pv_dictionary()[cam_num]+ADtype+":"
+    AD_SaveFileSetup(ADplugin,iex.BL.mda,**kwargs)
     AD_snap(ADplugin,**kwargs)
 
+
+
+
+##############################################################################################################
+##############################             Scanning with a camera           ##############################
+##############################################################################################################
+def cam_scan_setup(cam_num,ADtype='TIFF',**kwargs):
+    """
+    sets up the BL scanRecord to trigger the camera (trigger - 2)
+    """
+    ADplugin = _pv_dictionary()[cam_num]+ADtype+":"
+    ADplugin_ScanSetup(ADplugin,iex.BL.mda, **kwargs)  
+
 def cam_live(cam_num,ADtype='TIFF',**kwargs):
     """
     puts camera in no save and continuous
     a.k.a free run
 
     """
-    ADplugin = cam_pv_dictionary(cam_num)+ADtype+":"
-    AD_FreeRun(ADplugin,**kwargs)
+    ADplugin = _pv_dictionary()[cam_num]+ADtype+":"
+    AD_FreeRun(ADplugin,**kwargs)
\ No newline at end of file
diff --git a/build/lib/iexcode/instruments/shutters.py b/build/lib/iexcode/instruments/shutters.py
index 2afd842..39eb4da 100644
--- a/build/lib/iexcode/instruments/shutters.py
+++ b/build/lib/iexcode/instruments/shutters.py
@@ -4,7 +4,8 @@ main shutter and branch shutter functions
 from time import sleep
 from epics import caget, caput
 
-from iexcode.instruments.utilities import dateandtime, print_warning_message
+import iexcode.instruments.cfg as iex
+from iexcode.instruments.utilities import dateandtime
 
 
 ##############################################################################################################
@@ -67,13 +68,13 @@ def main_shutter_check_open():
 ################################             branch shutters            ##############################
 ##############################################################################################################
 
-def branch_shutter_status(branch,verbose=False):
+def branch_shutter_status(verbose=False):
     """
     checks on the status of the main shutter
     and returns shutter_open = True / False
     """
-    pvA="PA:29ID:S"+branch+"S_BLOCKING_BEAM.VAL"
-    pvB="PB:29ID:S"+branch+"S_BLOCKING_BEAM.VAL"
+    pvA="PA:29ID:S"+iex.BL.branch+"S_BLOCKING_BEAM.VAL"
+    pvB="PB:29ID:S"+iex.BL.branch+"S_BLOCKING_BEAM.VAL"
     #"ON" = 1 => shutter open
     status=caget(pvA)+caget(pvA)
     if status == 2:
@@ -83,20 +84,20 @@ def branch_shutter_status(branch,verbose=False):
 
     if verbose:
         status = 'Open' if shutter_open else 'Closed'
-        print(branch+"-shutter is "+status)
+        print(iex.BL.branch+"-shutter is "+status)
     return shutter_open
 
-def branch_shutter_close(branch):
+def branch_shutter_close():
     """
     closes current branch shutter
 
     Previously: Close_BranchShutter
     """
-    caput("PC:29ID:S"+branch+"S_CLOSE_REQUEST.VAL",1,wait=True,timeout=18000)
-    print("Closing "+branch+"-Shutter...")
+    caput("PC:29ID:S"+iex.BL.branch+"S_CLOSE_REQUEST.VAL",1,wait=True,timeout=18000)
+    print("Closing "+iex.BL.branch+"-Shutter...")
 
 
-def branch_shutter_open(branch):
+def branch_shutter_open():
     """
     Opens current branch shutter 
 
@@ -105,8 +106,8 @@ def branch_shutter_open(branch):
     """
     shutter_status = branch_shutter_status
     if shutter_status:
-        print(branch+"-Shutter already open...")
+        print(iex.BL.branch+"-Shutter already open...")
     else:
-        caput("PC:29ID:S"+branch+"S_OPEN_REQUEST.VAL",1,wait=True,timeout=18000)
-        print("Opening "+branch+"-Shutter...")
+        caput("PC:29ID:S"+iex.BL.branch+"S_OPEN_REQUEST.VAL",1,wait=True,timeout=18000)
+        print("Opening "+iex.BL.branch+"-Shutter...")
         
\ No newline at end of file
diff --git a/build/lib/iexcode/instruments/xrays.py b/build/lib/iexcode/instruments/xrays.py
index 783f6bc..7f70c3f 100644
--- a/build/lib/iexcode/instruments/xrays.py
+++ b/build/lib/iexcode/instruments/xrays.py
@@ -16,8 +16,8 @@ from iexcode.instruments.shutters import *
 from iexcode.instruments.gate_valves import *
 from iexcode.instruments.diagnostics import *
 from iexcode.instruments.m3r import *
-from iexcode.instruments.beamline import endstation_cams_enable
-from iexcode.instruments.utilities import print_warning_message,make_table, take_closest_value
+from iexcode.instruments.cameras import _enable_endstation_cameras
+from iexcode.instruments.utilities import print_warning_message,make_table
 from iexcode.instruments.current_amplifiers import ca_average
 from iexcode.instruments.Logfile import log_update
 
@@ -26,7 +26,7 @@ mpa = iex.mpa
 ##############################################################################################################
 ##############################            resets and detector lists         ##############################
 ##############################################################################################################
-def xrays_reset(verbose=True):
+def _xrays_reset(verbose=True):
     if verbose:
         print("resetting the mono limits")
     mono_limits_reset()
@@ -35,7 +35,7 @@ def xrays_reset(verbose=True):
     xray_motor_encoder_sync()
 
 
-def xrays_detector_list():
+def _xrays_detector_list():
     """
     defualt detectors for the APRES endstation
     used by: 
@@ -52,7 +52,7 @@ def xrays_detector_list():
     return ca_list
 
 
-def xrays_detector_dictionary():
+def _xrays_detector_dictionary():
     """
     returns a dictionary of the default detectors
     
@@ -87,30 +87,31 @@ def xrays_detector_dictionary():
 ##############################            get beamline info         ##############################
 ##############################################################################################################
 
-def xrays_get_all(verbose=False):
+def xrays_get_all(verbose=True):
     """
     gets info about current beamline setting
     returns a dictionary
 
     """
-    #global BL
     vals={}
-    print("\n===========================================================")
-    vals.update(ID_get_all(verbose=True))
-    vals.update(mono_get_all(verbose=True))
-    print("-----------------------------------------------------------")
-    vals.update(slits_get_all(verbose=True))
-    vals.update(FMB_mirror_get(0,verbose=True))
-    vals.update(FMB_mirror_get(1,verbose=True))
-    vals.update(FMB_mirror_get(3,verbose=True))
-    print("-----------------------------------------------------------")
-    vals.update({iex.BL.endstation:iex.BL.Motors.mprint()})
-    print(iex.BL.endstation+" = ",iex.BL.Motors.mprint())
+
+    if verbose:
+        print("-----------------------------------------------------------")   
+    vals.update(ID_get_all(verbose=verbose))
+    vals.update(mono_get_all(verbose=verbose))
     
-    print("===========================================================")
+    if verbose:
+        print("-----------------------------------------------------------")
+    vals.update(slits_get_all(verbose=verbose))
+    vals.update(FMB_mirror_get(0,verbose=verbose))
+    vals.update(FMB_mirror_get(1,verbose=verbose))
+    vals.update(FMB_mirror_get(3,verbose=verbose))
+    if verbose:
+        print("-----------------------------------------------------------")
+
     return vals
 
-def xrays_log_entries(**kwargs):
+def _xrays_log_entries(**kwargs):
     """
     Writes CSV file for the MDA scans with the following default parameters:
     FilePath='/home/beams/29IDUSER/Documents/User_Folders/UserName/'
@@ -229,11 +230,10 @@ def energy(hv_eV,slit_coeff=1,m3r=True,verbose=True):
     m3r => if True optimizes the mirror for the d-branch only
     Previously: Set_BL, energy
     """
-    #global BL
     if iex.BL.xrays:
-        if hv_eV != energy_range_check(hv_eV):
+        if hv_eV != _energy_range_check(hv_eV):
             message_string = 'request photon energy '+str(hv_eV)+' not with the allowed range'
-            message_string = '\n closest allowed energy is '+str(energy_range_check(hv_eV))
+            message_string = '\n closest allowed energy is '+str(_energy_range_check(hv_eV))
             print_warning_message(message_string)
 
 
@@ -255,7 +255,7 @@ def energy(hv_eV,slit_coeff=1,m3r=True,verbose=True):
         message_string = 'iex.BL.xrays = False, energy is not set'
         print_warning_message(message_string)
 
-def energy_range_min_max():
+def _energy_range_min_max():
     """
     returns the min,max energies for the current grating/ID setting
     """
@@ -265,31 +265,39 @@ def energy_range_min_max():
     hv_min = np.max(ID_min, mono_min)
     return hv_min,hv_max
 
-def energy_range_check(hv):
+def _energy_range_check(hv):
     """
     checks if the energy is within the allowed range for both the mono
     and the ID. If outside the ranges set it to the closest allowed value
 
     Previously: SetRange()
     """
-    hv_min,hv_max = energy_range_min_max()
+    hv_min,hv_max = _energy_range_min_max()
     hv = np.min(hv_max,hv)
     hv = np.max(hv_min,hv)
     return hv
 
-def mvid(val):
+def mvid_SP(val):
     """
     Sets the ID absolute set point (not optimized , mono & apertures stay fixed).
     
     to go to most flux use energy
     """
-    ID_SP_set()
+    ID_energy_set(val)
+    ID_SP_set(val)
+
+def mvid(val):
+    """
+    Sets the ID peak to val (calibrated).
+
+    """
+    ID_energy_set(val)
+
 
-def scan_ID(ID_sp_start,ID_sp_stop,ID_sp_step,**kwargs):
+def _scan_ID(ID_sp_start,ID_sp_stop,ID_sp_step,**kwargs):
     """
     scan the ID set point
     """
-    #global BL
     val_pv,rbv_pv = ID_scan_pvs()
     iex.BL.mda.fillin(val_pv,rbv_pv,ID_sp_start,ID_sp_stop,ID_sp_step,**kwargs)
 
@@ -384,7 +392,7 @@ def scanE(start,stop,step,ID_offset=0,mesh='stay',average_pnts=1,scan_dim=1,**kw
         scan_dim
         positioner_settling_time = 0.2
     """
-    #global BL
+
     mda = iex.BL.mda
     ca_average(average_pnts)
 
@@ -485,7 +493,6 @@ def scanXAS_BL(start_stop_step_lists,**kwargs):
     kwargs.setdefault("mcp",True)    
     kwargs.setdefault('execute',True)
 
-    #global BL
     scan_dim=kwargs['scan_dim']
         
     #Setting up the ScanRecord for Mono and ID in Table mode
@@ -631,7 +638,7 @@ def switch_branch(branch, force=False, shutter=True,scan_reset=True,enable_cams=
                 BL.mda.reset()
 
             if enable_cams:
-                endstation_cams_enable(branch)
+                _enable_endstation_cameras(branch)
 
     else:
         print_warning_message(branch+' is not a valid branch selection')
diff --git a/iexcode.egg-info/PKG-INFO b/iexcode.egg-info/PKG-INFO
index c7569a8..5719aab 100644
--- a/iexcode.egg-info/PKG-INFO
+++ b/iexcode.egg-info/PKG-INFO
@@ -5,8 +5,3 @@ Summary: python scripts to run 29id of the APS
 Home-page: https://github.com/xxx
 Maintainer: Jessica McChesney
 Maintainer-email: jmcchesn@anl.gov
-License: UNKNOWN
-Platform: UNKNOWN
-
-UNKNOWN
-
diff --git a/iexcode.egg-info/SOURCES.txt b/iexcode.egg-info/SOURCES.txt
index 969f22a..961d7f5 100644
--- a/iexcode.egg-info/SOURCES.txt
+++ b/iexcode.egg-info/SOURCES.txt
@@ -35,7 +35,6 @@ iexcode/instruments/diagnostics.py
 iexcode/instruments/electron_analyzer.py
 iexcode/instruments/encoders.py
 iexcode/instruments/files_and_folders.py
-iexcode/instruments/gate_valves.py
 iexcode/instruments/hxp_mirrors.py
 iexcode/instruments/m3r.py
 iexcode/instruments/remote_controlers.py
@@ -50,6 +49,7 @@ iexcode/instruments/staff.py
 iexcode/instruments/storage_ring.py
 iexcode/instruments/userCalcs.py
 iexcode/instruments/utilities.py
+iexcode/instruments/valves.py
 iexcode/instruments/vortex.py
 iexcode/instruments/xrays.py
 iexcode/macros/ARPES_macros.py
diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py
index 094d2ea..90001dd 100644
--- a/iexcode/instruments/ARPES.py
+++ b/iexcode/instruments/ARPES.py
@@ -8,6 +8,7 @@ from iexcode.instruments.IEX_endstations import Endstation
 from iexcode.instruments.cameras import _enable_endstation_cameras
 
 from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda
+from iexcode.instruments.Logfile import Logfile
 from iexcode.instruments.staff import staff_detector_dictionary
 from iexcode.instruments.xrays import _xrays_detector_dictionary, _xrays_reset, xrays_get_all
 
@@ -17,7 +18,7 @@ from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs
 
 from iexcode.instruments.Motors import Motors
 from iexcode.instruments.current_amplifiers import *
-from iexcode.instruments.gate_valves import valve_close, branch_valves
+from iexcode.instruments.valves import branch_valve_close
 from iexcode.instruments.shutters import branch_shutter_close
 
 #branch specific
@@ -71,7 +72,7 @@ def ARPES_init(*userName,**kwargs):
         folders_ARPES(user_name,**kwargs)
 
         #update for default scanRecord advanced parameters
-        iex.BL.mda.log('ARPES',user_name,_ARPES_log_header(),_ARPES_log_entries)
+        iex.BL.mda.log=Logfile('ARPES',user_name,_ARPES_log_header(),_ARPES_log_entries)
 
     #EA
     if EA.connected: 
@@ -636,16 +637,18 @@ def ARPES_safe_state(**kwargs):
     global EA
     
     if kwargs["EA_off"]:
-        try:
+        if EA.connected: 
             EA.off(quiet=False)
-        except:
+        else:
             print('EA is not running, visually confirm HV is off')
+    
+    if kwargs['shutter_close']:
+        branch_shutter_close()
 
     if kwargs['valve_close']:
-       valve_close(branch_valves('c'), verbose=True)
+       branch_valve_close()
+
 
-    if kwargs['shutter_close']:
-        branch_shutter_close('c')
 
 ##############################################################################################################
 ##############################              ARPES motors       ##############################
diff --git a/iexcode/instruments/IEX_endstations.py b/iexcode/instruments/IEX_endstations.py
index 6827863..d937acd 100644
--- a/iexcode/instruments/IEX_endstations.py
+++ b/iexcode/instruments/IEX_endstations.py
@@ -43,6 +43,7 @@ class Endstation:
         
         BL = Endstation()
             BL.endstation => endstation_name
+            BL.branch => BL branch 'c' or 'd' only (used for shutter checks)
             BL.xrays => True/False 
             BL.mode => 'user'/'staff' previously: BL_Mode_Set
             BL.folder => 'b','c','d'
@@ -57,6 +58,7 @@ class Endstation:
         """
        
         self.endstation = None
+        self.branch = None
         self.ioc = scan_ioc
         self.folder = None
         self.prefix = None
@@ -88,11 +90,14 @@ class Endstation:
                 if endstation_name == 'ARPES':
                     self.folder = 'c'
                     self.prefix = 'ARPES_'
+                    self.branch = 'c'
                 elif endstation_name == 'Kappa':
                     self.folder = 'd'
                     self.prefix = 'Kappa_'
+                    self.branch = 'd'
                 #elif endstation_name == 'Octupole':
                     #self.folder = 'e'
+                    self.branch = 'd'
                 else:
                     print('folder and prefix not set')
 
@@ -117,15 +122,21 @@ class Endstation:
 ##############################################################################################################
 def BL_ioc():
     """
-    returns the branch from the Endstation instance
+    returns the ioc from the Endstation instance
     """
     return iex.BL.ioc
 
+def BL_branch():
+    """
+    returns the branch from the Endstation instance
+    """
+    return iex.BL.branch
+
 def BL_mode():
     """
     returns the beamline mode, User / Staff / No_Xray
     """
-    return iex.BL.ioc
+    return iex.BL.mode
 
 def BL_mda_prefix():
     """
diff --git a/iexcode/instruments/Kappa.py b/iexcode/instruments/Kappa.py
index b329f6d..edd6198 100644
--- a/iexcode/instruments/Kappa.py
+++ b/iexcode/instruments/Kappa.py
@@ -19,7 +19,7 @@ from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs
 
 from iexcode.instruments.Motors import Motors
 from iexcode.instruments.current_amplifiers import SRS, ca_reset_all, Keithley_pv
-from iexcode.instruments.gate_valves import valve_close, branch_valves
+from iexcode.instruments.valves import branch_valve_close
 from iexcode.instruments.shutters import branch_shutter_close
 
 #branch specific
@@ -876,9 +876,11 @@ def Kappa_safe_state(**kwargs):
         except:
             print('MPA is not running')
 
+    if kwargs['shutter_close']:
+        branch_shutter_close()
+    
     if kwargs['valve_close']:
-       valve_close(branch_valves('d'), verbose=True)
+       branch_valve_close()
+
 
-    if kwargs['shutter_close']:
-        branch_shutter_close('d')
     
\ No newline at end of file
diff --git a/iexcode/instruments/cameras.py b/iexcode/instruments/cameras.py
index 87c90a9..e91f8d3 100644
--- a/iexcode/instruments/cameras.py
+++ b/iexcode/instruments/cameras.py
@@ -1,9 +1,9 @@
 
+import time 
 from epics import caget,caput,PV
 
 import iexcode.instruments.cfg as iex
 from iexcode.instruments.AD_utilities import *
-from iexcode.instruments.IEX_endstations import *
 
 ##############################################################################################################
 ##############################              Camera PV dictionary            ##############################
@@ -39,19 +39,22 @@ def _enable_endstation_cameras(unused_off=True):
     cam_dict={'ARPES':[0,1,2],'Kappa':[3,4,6]}  # index of cam_list 
 
     d=_pv_dictionary()
-    for num in d.keys: 
+    for num in d.keys(): 
         pv=d[num]+"cam1:Acquire"   
         #camera in list
         if num in cam_dict[endstation]:
+            #two connected to deal with network traffic
+            PV(pv).connected
+            time.sleep(0.1)
             if PV(pv).connected:  
-                pv.put('Acquire')
+                caput(pv,'Acquire')
             else:
                 print(d[num]+" ioc in not running")
         #camera not in list
         else:
             if unused_off:
                 if PV(pv).connected:  
-                    pv.put('Done')
+                    caput(pv,'Done')
 
 
 ##############################################################################################################
diff --git a/iexcode/instruments/gate_valves.py b/iexcode/instruments/gate_valves.py
deleted file mode 100644
index 1e122c5..0000000
--- a/iexcode/instruments/gate_valves.py
+++ /dev/null
@@ -1,35 +0,0 @@
-from epics import caget, caput
-
-def branch_valves():
-    """
-    returns a dictionary of the gate valves for a given branch
-
-    used by close_valve and safe_state
-    """
-    
-    GVs={
-        'c':('GV10'),
-        'd':('GV14'),
-        'e':()
-        }
-    return GVs
-    
-def valve_close(GV, verbose=True):
-    """
-    closes the gate valve ('GV10', 'GV14'), EPS nomenclature
-
-    Previously: Close_DValve,Close_DValve
-    """
-    caput("29id:BLEPS:"+GV+":CLOSE.VAL",1,wait=True,timeout=18000)
-    if verbose:
-        print("Closing gate valve: "+GV+"...")
-
-def valve_open(GV, verbose=True):
-    """
-    closes the gate valve ('GV10', 'GV14'), EPS nomenclature
-
-    Previously: Close_DValve,Close_DValve
-    """
-    caput("29id:BLEPS:"+GV+":OPEN.VAL",1,wait=True,timeout=18000)
-    if verbose:
-        print("Opening gate valve: "+GV+"...")
\ No newline at end of file
diff --git a/iexcode/instruments/shutters.py b/iexcode/instruments/shutters.py
index 2afd842..39eb4da 100644
--- a/iexcode/instruments/shutters.py
+++ b/iexcode/instruments/shutters.py
@@ -4,7 +4,8 @@ main shutter and branch shutter functions
 from time import sleep
 from epics import caget, caput
 
-from iexcode.instruments.utilities import dateandtime, print_warning_message
+import iexcode.instruments.cfg as iex
+from iexcode.instruments.utilities import dateandtime
 
 
 ##############################################################################################################
@@ -67,13 +68,13 @@ def main_shutter_check_open():
 ################################             branch shutters            ##############################
 ##############################################################################################################
 
-def branch_shutter_status(branch,verbose=False):
+def branch_shutter_status(verbose=False):
     """
     checks on the status of the main shutter
     and returns shutter_open = True / False
     """
-    pvA="PA:29ID:S"+branch+"S_BLOCKING_BEAM.VAL"
-    pvB="PB:29ID:S"+branch+"S_BLOCKING_BEAM.VAL"
+    pvA="PA:29ID:S"+iex.BL.branch+"S_BLOCKING_BEAM.VAL"
+    pvB="PB:29ID:S"+iex.BL.branch+"S_BLOCKING_BEAM.VAL"
     #"ON" = 1 => shutter open
     status=caget(pvA)+caget(pvA)
     if status == 2:
@@ -83,20 +84,20 @@ def branch_shutter_status(branch,verbose=False):
 
     if verbose:
         status = 'Open' if shutter_open else 'Closed'
-        print(branch+"-shutter is "+status)
+        print(iex.BL.branch+"-shutter is "+status)
     return shutter_open
 
-def branch_shutter_close(branch):
+def branch_shutter_close():
     """
     closes current branch shutter
 
     Previously: Close_BranchShutter
     """
-    caput("PC:29ID:S"+branch+"S_CLOSE_REQUEST.VAL",1,wait=True,timeout=18000)
-    print("Closing "+branch+"-Shutter...")
+    caput("PC:29ID:S"+iex.BL.branch+"S_CLOSE_REQUEST.VAL",1,wait=True,timeout=18000)
+    print("Closing "+iex.BL.branch+"-Shutter...")
 
 
-def branch_shutter_open(branch):
+def branch_shutter_open():
     """
     Opens current branch shutter 
 
@@ -105,8 +106,8 @@ def branch_shutter_open(branch):
     """
     shutter_status = branch_shutter_status
     if shutter_status:
-        print(branch+"-Shutter already open...")
+        print(iex.BL.branch+"-Shutter already open...")
     else:
-        caput("PC:29ID:S"+branch+"S_OPEN_REQUEST.VAL",1,wait=True,timeout=18000)
-        print("Opening "+branch+"-Shutter...")
+        caput("PC:29ID:S"+iex.BL.branch+"S_OPEN_REQUEST.VAL",1,wait=True,timeout=18000)
+        print("Opening "+iex.BL.branch+"-Shutter...")
         
\ No newline at end of file
diff --git a/iexcode/instruments/valves.py b/iexcode/instruments/valves.py
new file mode 100644
index 0000000..12ca77f
--- /dev/null
+++ b/iexcode/instruments/valves.py
@@ -0,0 +1,82 @@
+from epics import caget, caput
+
+import iexcode.instruments.cfg as iex
+
+branch_GVs={
+    'c':('10'),
+    'd':('14'),
+    }
+
+def branch_valve_close():
+    """
+    closes the endstation valve for the current branch
+    """
+    GV = branch_GVs[iex.BL.branch]
+    valve_close(GV, verbose=True)
+    
+def branch_valve_open():
+    """
+    closes the endstation valve for the current branch
+    """
+    GV = branch_GVs[iex.BL.branch]
+    valve_open(GV, verbose=True)
+
+    
+def valve_close(GV, verbose=True):
+    """
+    closes the gate valve ('GV10', 'GV14'), EPS nomenclature
+
+    Previously: Close_DValve,Close_DValve
+    """
+    pv = "29id:BLEPS:GV"+str(GV).zfill(2)+":CLOSE.VAL"
+    status = valve_status(GV)
+    if status == 'closed':
+        message = "Gate valve: "+GV+" is already closed"
+    elif status == 'open':
+        caput(pv,1,wait=True,timeout=18000)
+        message = "Closing gate valve: "+GV+"..."
+    else:
+        caput(pv,1,wait=True,timeout=18000)   
+        message = "Gate valve: "+GV+" was in an error state, trying to close..."
+    if verbose:
+        print(message)
+
+def valve_open(GV, verbose=True):
+    """
+    closes the gate valve ('GV10', 'GV14'), EPS nomenclature
+
+    Previously: Close_DValve,Close_DValve
+    """
+    pv = "29id:BLEPS:GV"+str(GV).zfill(2)+":OPEN.VAL"
+    status = valve_status(GV)
+    if status == 'open':
+        message = "Gate valve: "+GV+" is already open"
+    elif status == 'closed':
+        caput(pv,1,wait=True,timeout=18000)
+        message = "Opening gate valve: "+GV+"..."
+    else:
+        caput(pv,1,wait=True,timeout=18000)   
+        message = "Gate valve: "+GV+" was in an error state, trying to open..."
+    if verbose:
+        print(message)
+
+def valve_status(GV,verbose=True):
+    """
+    returns the current status ('open','closed','error')
+    """
+    open_status = bool(caget("29id:BLEPS:GV"+str(GV).zfill(2)+":OPENED:STS"))
+    closed_status = bool(caget("29id:BLEPS:GV"+str(GV).zfill(2)+":CLOSED:STS"))
+
+    if open_status == True:
+        if closed_status == False:
+            status = 'open'
+        else:
+            status = 'error'
+
+    if closed_status == True:
+        if open_status == False:
+            status = 'closed'
+        else:
+            status = 'error'
+    
+    return status
\ No newline at end of file
-- 
GitLab