#! /usr/bin/env mpenv # # This script counts for the requested number of seconds and then # reads out the scalers. # import time import Mp import MpCa if ( len(sys.argv) != 4 ): print "" print "Usage: mpca_count count_time scaler_name" print "" sys.exit(0); counting_time = float( sys.argv[2] ) scaler_name = sys.argv[3] # Construct a list of scaler channel PVs. nch = MpCa.PV( "%s.NCH" % scaler_name ).caget() scaler_list = [] for i in range(nch-1): pv = MpCa.PV( "%s.S%d" % (scaler_name, i+2) ) scaler_list.append( pv ) # Get the timer frequency. freq = MpCa.PV( "%s.FREQ" % scaler_name ).caget() # If the scaler is counting, then stop it. cnt_pv = MpCa.PV( "%s.CNT" % scaler_name ) cnt_pv.caput( 0 ) print "Counting with scaler '%s' for %g seconds." \ % ( scaler_name, counting_time ) # Set the preset time. tp_pv = MpCa.PV( "%s.TP" % scaler_name ) tp_pv.caput( counting_time ) # Get the S1 counter PV (the timer channel). s1_pv = MpCa.PV( "%s.S1" % scaler_name ) # Start counting. cnt_pv.caput( 1 ) # Wait for the scaler to stop counting. while (1): cnt = cnt_pv.caget() if ( cnt == 0 ): break s1_value = s1_pv.caget() value_string = "%.3f " % ( s1_value / freq ) print value_string, for pv in scaler_list: value = pv.caget() value_string = "%8d " % value print value_string, print "" time.sleep( 1.0 ) # Counting is complete, so display the final values. s1_value = s1_pv.caget() value_string = "%.3f " % ( s1_value / freq ) print value_string, for pv in scaler_list: value = pv.caget() value_string = "%8d " % value print value_string, print "" print "Done!"