toolnew = GetSelectedTool()toolold = GetOemdro(824)xx = GetToolChangeStart( 0 )yy = GetToolChangeStart( 1 )zz = GetToolChangeStart( 2 )If (toolnew = toolold) Thenmessage("tool is already in use!")EndEnd IfIf (toolnew < 1)Or(toolnew >999 ) ThenSetCurrentTool(toolold)MsgBox ("wrong tool number!")message("wrong tool number!")Call Code("M30")EndEnd Ifx = GetUserDRO(1200)y = GetUserDRO(1201)z = GetUserDRO(1202)Code "G00 G53 Z" & zWhile IsMoving () 	'pause to allow Z axis to move to change positionSleep 100 WendCode "G00 G53 X" & x & "Y" & yWhile IsMoving ()	'pause to allow XY axis to move to change positionSleep 100WendSlot1 = GetUserDRO(1101)Slot2 = GetUserDRO(1102)Slot3 = GetUserDRO(1103)Slot4 = GetUserDRO(1104)Slot5 = GetUserDRO(1105)Slot6 = GetUserDRO(1106)Toolpos = 0If (toolnew = Slot1) ThenToolpos = 1End IfIf (toolnew = Slot2) ThenToolpos = 2End IfIf (toolnew = Slot3) ThenToolpos = 3End IfIf (toolnew = Slot4) ThenToolpos = 4End IfIf (toolnew = Slot5) ThenToolpos = 5End IfIf (toolnew = Slot6) ThenToolpos = 6End IfIf (Toolpos = 0) Thenmessage("tool not in carousel!")MsgBox ("tool not in carousel!")Call Code("M30")endend IfIf IsActive(INPUT1) thenIf (Toolpos = 1) ThenSendSerial("B0000133E9>7R25")end IfIf (Toolpos = 2) ThenSendSerial("B0000133E:?7R25")end IfIf (Toolpos = 3) ThenSendSerial("B0000133E;08R25")end IfIf (Toolpos = 4) ThenSendSerial("B0000133E<18R25")end IfIf (Toolpos = 5) ThenSendSerial("B0000133E=28R25")end IfIf (Toolpos = 6) ThenSendSerial("B0000133E>38R25")end IfElseMessage("Toolchange failed")MsgBox ("Toolchange failed")DoOEMButton(1021)endEnd Ifmessage("tool change is running !")SetCurrentTool( toolnew )Code "G43"SetTimer(10)While Not IsActive(INPUT1) 	'pause loop to allow carousel to reference		Sleep 1000If GetTimer(10) > 17 Then	Message ("ATC datum failed at carousel index stage")	MsgBox ("ATC Carousel failed to reference - press OK to abort")	Exit SubEnd If	WendCode"G00 X" & xx & "Y" & yyWhile IsMoving ()Sleep 100WendEnd                                       