esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% MOTCOUNT.MAC 
#%NAME% Sets counters for motor positions 
#
#%CATEGORY% Positioning
#
#%DESCRIPTION%
# This macro file allows to define counters to report motor positions.
# This may be useful for DC motors, steppermotor with encoders and others
# to survey if the position remains constant during a scan ( timescan or
# other ). 
#
#%END%

#%UU% [motor-mne cnt-mne [ motor-mne cnt-mne..]]
#%MDESC%
#  Without arguments it will prompt the user for motor and counter
#  mnemonics.  
#  Otherwise it will interpret the parameteres and set global variable.
def motcountsetup '{
   global MOTC_MOT MOTC_CT MOTC_NO
   global MOTC_ON
 
   if (!$#) {
      MOTC_NO = getval("How many counter/motor do you want to define",MOTC_NO)
      for (i=0;i<MOTC_NO;i++) {
        MOTC_MOT[i] = getval(sprintf("\n%d\tMotor mnemonic",i+1),MOTC_MOT[i]) 
        MOTC_CT[i] = getval("\tCounter mnemonic",MOTC_CT[i]) 
      }
   } else {
        MOTC_NO = split("$*",param)/2
        for (i=0;i<MOTC_NO;i++) {
            MOTC_MOT[i] = param[i*2]
            MOTC_CT[i] = param[i*2+1]
        }
   }

   if (whatis("MOTC_ON") & 0x8000000 ) {
         motcon
   }
   blmenuadd("Counter on motors","","motcbody","_motc_")

   if (MOTC_ON) {
        tty_cntl("md")
        printf("\nWARNING\n")
        tty_cntl("me")
        printf("  Counters on motors: ACTIVE\n")
        printf("  Remember that this may add extra overhead on\n")
        printf("  every scan point. If you do not need\n")
        printf("  this functionality ")
        tty_cntl("us")
        printf("take it out of setup file") 
        tty_cntl("ue")
        printf(".\n")
        printf("  Or type ");tty_cntl("us");printf("motcoff")
        tty_cntl("ue");printf(".\n")
   }
   setup_tail("motc")
}'

#%IU%
#%MDESC%
#
def motcunsetup '{
    cdef("","","_motc_","delete")
    motcoff
}'

#%UU%
#%MDESC%
#  Sets active the functionality for counters on motors
def motcon '{
    MOTC_ON = 1
    cdef("user_getcounts","motc_get\n","motc")
 
    if ( USER == "opid22" ) {
       # ID22 needs more precision in motor position
       rdef_loop
       rdef_showcnts
    }
}'

#%IU%
#%MDESC%
# 
def motc_get '{
    sync;get_angles  
    for (i=0;i<MOTC_NO;i++) {
       local motnum ctnum
       motnum = motor_num(MOTC_MOT[i])
       ctnum = cnt_num(MOTC_CT[i])
       if ((ctnum != -1) && (motnum != -1) ) {
          S[ctnum] = A[motnum]*1
       }
    }
}'

#%UU%
#%MDESC%
# Sets inactive the functionality without changing the settings.
def motcoff '{

    MOTC_ON = 0

    for (ii=0; ii<MOTC_NO; ii++) {
         ctnum = cnt_num(MOTC_CT[ii])
         S[ctnum] = 0
    }

    if (USER == "opid22") {
       rdef_loop_back
       rdef_showcnts_back
    }

    cdef("","","motc","delete")

}'



#%IU%
#%MDESC%
#
def motcbody(mode) '{
  if (mode==1) {
     if (MOTC_ON) {
         motcoff
     } else {
         motcon
     }
  }
  return(sprintf("%s",MOTC_ON?"On":"Off"))

}'

#%IU%
def rdef_showcnts '{
    rdef show_cnts \'{
        local   i

        get_counts
        printf("\n%s\n\n", date())
        for (i=0;i<COUNTERS;i++)
                if (cnt_name(i) != "unused")
                        printf("%12s = %g%s\n", cnt_name(i), S[i], \
                   i != sec && S[sec]? sprintf(" (%g/s)", S[i] / S[sec]):"")
    }\'
}'

#%IU%
def rdef_showcnts_back '{
    rdef show_cnts \'{
        local   i

        get_counts
        printf("\n%s\n\n", date())
        for (i=0;i<COUNTERS;i++)
                if (cnt_name(i) != "unused")
                        printf("%12s = %g%s\n", cnt_name(i), S[i], \
                   i != sec && S[sec]? sprintf(" (%g/s)", S[i] / S[sec]):"")
    }\'
}'


#%IU%
def rdef_loop '{
   rdef _loop \'{
	local z cols i
	if (!set_sim(-1) && _sleep) {
		do_sleep _sleep
	}
	measure0
	scan_count _ctime
	measure1
	measure2
	z = _ctime < 0? sec:MON
	T_AV += DEGC;
	if (z >= 0)
		MT_AV += S[z]
	printf("%3d %s%8.0f ", NPTS,VPRNT,S[DET])
	if (MON >= 0)
		printf("%8.0f ", S[MON])
	printf("%10.6g ", S[sec])
	tty_move(-10000, -10000)
	cols = int((COLS-length(VPRNT)-length(Pout)-24-9*(MON >= 0)) / 9)
	for (i = 0; i < COUNTERS && cols > 0; i++) {
		if (i!=DET && i !=MON && i!=sec && cnt_name(i) != "unused"){
			printf("%8.8g ", S[i])
			cols--
		}
	}
	printf("%s\n", Pout)
	if (DATAFILE != "") {
		fprintf(DATAFILE,"%s%s%d",FPRNT,Fout,(TIME_END=time())-EPOCH)
		for (i=0;i<COUNTERS;i++)
			if (i != z && i != DET && cnt_name(i) != "unused")
				fprintf(DATAFILE," %.8g",S[i])
		if (z >= 0)
			fprintf(DATAFILE," %.8g",S[z])
		fprintf(DATAFILE," %.8g\n",S[DET]);
	}
        user_scan_loop
   }\'
}'

#%IU%
def rdef_loop_back '{
   rdef _loop \'{
	local z cols i
	if (!set_sim(-1) && _sleep) {
		do_sleep _sleep
	}
	measure0
	scan_count _ctime
	measure1
	measure2
	z = _ctime < 0? sec:MON
	T_AV += DEGC;
	if (z >= 0)
		MT_AV += S[z]
	printf("%3d %s%8.0f ", NPTS,VPRNT,S[DET])
	if (MON >= 0)
		printf("%8.0f ", S[MON])
	printf("%10.6g ", S[sec])
	tty_move(-10000, -10000)
	cols = int((COLS-length(VPRNT)-length(Pout)-24-9*(MON >= 0)) / 9)
	for (i = 0; i < COUNTERS && cols > 0; i++) {
		if (i!=DET && i !=MON && i!=sec && cnt_name(i) != "unused"){
			printf("%8.4g ", S[i])
			cols--
		}
	}
	printf("%s\n", Pout)
	if (DATAFILE != "") {
		fprintf(DATAFILE,"%s%s%d",FPRNT,Fout,(TIME_END=time())-EPOCH)
		for (i=0;i<COUNTERS;i++)
			if (i != z && i != DET && cnt_name(i) != "unused")
				fprintf(DATAFILE," %g",S[i])
		if (z >= 0)
			fprintf(DATAFILE," %g",S[z])
		fprintf(DATAFILE," %g\n",S[DET]);
	}
        user_scan_loop
   }\'
}'

#%MACROS%
#%IMACROS%
#%AUTHOR% Vicente Rey - BLISS group - January 1998
# taken out all fprintf(PRINTER , Holger, 9.12.2004
#%TOC%