' vi: syntax=basic noet

' ---------------------------------------------
' --------------- HomeAsync.ab ----------------
' ---------------------------------------------
'
' This program homes a variable number of axes,
' based upon the settings of some global variables.
'
' This program should be compiled and loaded to
' the controller file system (HomeAsync.bcx) so
' that the program can be executed by another program
' in a different task. By doing this, the home
' command will not consume the task, and status can
' be monitored while this home is running.
'
' An example of how this program would be executed
' from another task:
'
' IGLOBAL(32) = 3   ' 3 axes
' IGLOBAL(33) = 0   ' 'X' axis
' IGLOBAL(34) = 2   ' 'Z' axis
' IGLOBAL(35) = 5   ' 'B' axis
'
' ' run the program on the Auxiliary task (5)
' PROGRAM RUN 5, "HomeAsync.bcx"
'
' -----------------------------------------------

DIM NumAxes AS INTEGER
DIM Axis1 AS INTEGER
DIM Axis2 AS INTEGER

NumAxes = IGLOBAL(32)
Axis1 = IGLOBAL(33)
Axis2 = IGLOBAL(34)

' Make sure you always home to the lower limit

IF NumAxes = 1 THEN
   ' setparm @Axis1,HomeSetup,0x0
	' MOVETOLIM @Axis1 CCW
	HOME @Axis1
ELSEIF NumAxes = 2 THEN
    setparm @Axis1,HomeSetup,0x0
    setparm @Axis2,HomeSetup,0x0
	HOME @Axis1 @Axis2
ELSE
    ' This code does nothing, but
    ' an error condition could be indicated back
    ' to the other task with an other global
    ' variable.
END IF
