A rudimentary timer (low granularity), that doesn't lock IGOR up.

Average rating
(0 votes)

Sometimes when you are doing something that depends on waiting for a period of time (such as data acquisition) you need a timer that doesn't lock IGOR up. This timer can be started by calling startwait, with a given wait period. You can then use waitstatus() (probably from another background task) to see if the timer has finished. If waitStatus returns 1, then the waiting period isn't over. You can stop the waiting period by calling stopWait(). This has low granularity, as the background task fires once a second.

//a background task that you can use to wait for a given timeperiod.  This is probably called from
//another background task.  This is useful if you don't want to lock IGOR up.
 
Function startwait(timeout)
	variable timeout
	variable/g root:endtime
	NVAR endtime = root:endtime
 
	endtime = datetime+timeout
 
	CtrlNamedBackground waiter,period=60,proc=waittask
	CtrlNamedBackground waiter, start
End
 
Function stopwait()
	ctrlnamedbackground waiter,stop=1
	killvariables root:endtime
ENd
 
Function waitStatus()
	ctrlnamedbackground waiter,status
	return numberbykey("RUN",S_info)
End
 
Function waittask(s)
	STRUCT WMBackgroundStruct &s
	NVAR endtime = root:endtime
	if(datetime > endtime)
		stopwait()
		return 1
	endif
	return 0
End

Back to top