#!/bin/bash

case "$1" in
'100')
OFF=ACSW:LI20:NW14:13POWEROFF
ON=ACSW:LI20:NW14:13POWERON;;
'101')
OFF=ACSW:LI20:NW14:16POWEROFF
ON=ACSW:LI20:NW14:16POWERON;;
'102')
OFF=ACSW:LI20:NW14:18POWEROFF
ON=ACSW:LI20:NW14:18POWERON;;
'104')
OFF=ACSW:LI20:NW14:21POWEROFF
ON=ACSW:LI20:NW14:21POWERON;;
'2432')
OFF=ACSW:LI20:NW13:18POWEROFF
ON=ACSW:LI20:NW13:18POWERON;;
'3075')
OFF=ACSW:LI20:NW13:19POWEROFF
ON=ACSW:LI20:NW13:19POWERON;;
'3158')
OFF=ACSW:LI20:NW13:20POWEROFF
ON=ACSW:LI20:NW13:20POWERON;;
'3180')
OFF=ACSW:LI20:NW13:21POWEROFF
ON=ACSW:LI20:NW13:21POWERON;;
'3208')
OFF=ACSW:LI20:NW13:22POWEROFF
ON=ACSW:LI20:NW13:22POWERON;;
'3202')
OFF=ACSW:LI20:NW13:23POWEROFF
ON=ACSW:LI20:NW13:23POWERON;;
'3230')
OFF=ACSW:LI20:NW13:24POWEROFF
ON=ACSW:LI20:NW13:24POWERON;;
'3300')
OFF=ACSW:LI20:NW13:10POWEROFF
ON=ACSW:LI20:NW13:10POWERON;;
'3301')
OFF=ACSW:LI20:NW13:9POWEROFF
ON=ACSW:LI20:NW13:9POWERON;;
'3302')
OFF=ACSW:LI20:NW13:8POWEROFF
ON=ACSW:LI20:NW13:8POWERON;;
'3303')
OFF=ACSW:LI20:NW13:11POWEROFF
ON=ACSW:LI20:NW13:11POWERON;;
'3304')
OFF=ACSW:LI20:NW13:12POWEROFF
ON=ACSW:LI20:NW13:12POWERON;;
'3305')
OFF=ACSW:LI20:NW13:13POWEROFF
ON=ACSW:LI20:NW13:13POWERON;;
'3306')
OFF=ACSW:LI20:NW13:14POWEROFF
ON=ACSW:LI20:NW13:14POWERON;;
'3307')
OFF=ACSW:LI20:NW13:1POWEROFF
ON=ACSW:LI20:NW13:1POWERON;;
'3308')
OFF=ACSW:LI20:NW13:2POWEROFF
ON=ACSW:LI20:NW13:2POWERON;;
'3309')
OFF=ACSW:LI20:NW13:3POWEROFF
ON=ACSW:LI20:NW13:3POWERON;;
'3310')
OFF=ACSW:LI20:NW13:4POWEROFF
ON=ACSW:LI20:NW13:4POWERON;;
'3311')
OFF=ACSW:LI20:NW13:5POWEROFF
ON=ACSW:LI20:NW13:5POWERON;;
'3312')
OFF=ACSW:LI20:NW13:6POWEROFF
ON=ACSW:LI20:NW13:6POWERON;;
'3313')
OFF=ACSW:LI20:NW13:17POWEROFF
ON=ACSW:LI20:NW13:17POWERON;;
esac

caput $OFF 1
sleep 10
caput $ON 1

COUNTER=0
while [ $COUNTER -lt 60 ]; do
	
	if [ $1 -lt 3300 ]
	then
		if [ $1 -lt 105 ]
		then
			x=$(caget -nt PROF:LI20:B$1:AsynIO.CNCT)
		else
			x=$(caget -nt PROF:LI20:$1:AsynIO.CNCT)
		fi
	else
		x=$(caget -nt EXPT:LI20:$1:AsynIO.CNCT)
	fi
	
	if [ $x -eq 1 ]
	then
		break
	fi
	
	echo $x
	sleep 1
	let COUNTER=COUNTER+1
done

if [ $1 -lt 3300 ]
then
	if [ $1 -lt 105 ]
	then
                caput PROF:LI20:B$1:Acquisition 0
                caput PROF:LI20:B$1:BinX 1
                caput PROF:LI20:B$1:BinY 1
                caput PROF:LI20:B$1:DataType 1
                caput PROF:LI20:B$1:TriggerMode 1
                caput PROF:LI20:B$1:Acquisition 1
                caput PROF:LI20:B$1:AcquireTime 5e-5
	else
		caput PROF:LI20:$1:Acquisition 0
		caput PROF:LI20:$1:BinX 1
		caput PROF:LI20:$1:BinY 1
		caput PROF:LI20:$1:DataType 1
		caput PROF:LI20:$1:TriggerMode 1
		caput PROF:LI20:$1:Acquisition 1
		caput PROF:LI20:$1:AcquireTime 5e-5
	fi
else
        caput EXPT:LI20:$1:Acquisition 0
        caput EXPT:LI20:$1:BinX 1
        caput EXPT:LI20:$1:BinY 1
        caput EXPT:LI20:$1:DataType 1
        caput EXPT:LI20:$1:TriggerMode 1
        caput EXPT:LI20:$1:Acquisition 1
	caput EXPT:LI20:$1:AcquireTime 5e-5
fi

if [ $1 -eq 3301 ]
then
        caput EXPT:LI20:$1:AcquireTime 0.001
fi
