#! /bin/tcsh -f # # Adjust Dolan-Jenner light levels # -James Holton 8-28-02 # # if(! $?beamline) then # default to beamline this computer belongs to setenv beamline `beamline.com` if($status) then echo "ERROR: $beamline" exit 9 endif endif #if(! $?beamline) setenv beamline 831 set tclsh = tclsh if("$beamline" =~ 82?) set tclsh = "ssh mcfuser@bl${beamline}c tclsh8.2" set host = wago1 if("$beamline" == 1231) set host = px ########################################################## set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) then alias echo /bin/echo set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo '/bin/echo -e' set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo /usr/bin/echo set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo '/bin/echo \!* | awk '\''/^-n/{printf "%s", substr($0,4) ; exit} {print}'\' set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) then echo "ERROR: echo command is broken" exit 9 endif endif #######################################################3 set light = "" set intensity = 50 foreach arg ( $* ) if("$arg" =~ [0-9]*) then if("$arg" =~ [12]) then set light = "$arg" continue endif if("$arg" =~ *%) then if("$light" == "") set light = 1 set intensity = $arg continue endif if(("$arg" =~ 0.[0-9]*)||("$arg" =~ 1.0*)) then if("$light" == "") set light = 1 set power = `echo $arg | awk '{print $1*100}'` continue endif endif end if(! $?power) then # convert desired intensity into a power level set power = `echo $intensity | awk '{p=51.5 + 0.003768*($1^2)} $1+0>=100{p=100} $1+0<=1{p=0} {print p}'` endif #echo "power = $power" set volts = `echo $intensity | awk '{print $1*5/100}'` set power = `echo $power | awk '{printf "%d", $1*1.27}'` if("$light" != "") then # set the chosen light to the desired level pxmotor.com Illuminator \#$light $volts >& /dev/null if(! $status) goto report # that didn't work, try using the wago echo "$light $power" |\ awk '$1>1{$1+=1} {print "set sock [socket '$host' 502]";\ print "fconfigure $sock -translation binary"\ printf "puts -nonewline $sock "\ print "[format \"\\000\\000\\000\\000\\000\\010\\000\\020\\002%c\\000\\001%c%c\"", $1,$2,$2, "]";\ print "close $sock"; print "exit"}' |\ $tclsh | od -c > /dev/null endif report: # read the current light power settings pxmotor.com Illuminator \#1 |& head -1 | awk '$NF~/^[0-9]/{printf "light #1 is at: %d%%\n",$NF/5*100}' pxmotor.com Illuminator \#2 |& head -1 | awk '$NF~/^[0-9]/{printf "light #2 is at: %d%%\n",$NF/5*100}' if(! $status) exit # read the current light power settings cat << EOF | $tclsh set sock [socket $host 502] fconfigure \$sock -buffering none -translation binary puts -nonewline \$sock "\000\000\000\000\000\006\000\003\002\001\000\002" puts -nonewline \$sock "\000\000\000\000\000\006\000\003\002\003\000\002" set byte [read \$sock 9] set byte [read \$sock 1] binary scan "\$byte" c power puts [format "light #1 is at: %d%%" [expr int(\$power/1.27)]] set byte [read \$sock 12] set byte [read \$sock 1] binary scan "\$byte" c power puts [format "light #2 is at: %d%%" [expr int(\$power/1.27)]] EOF