I want to change my tools and make the height control with this macro but When I run this macro my computer freezing.What is the problem with this code.I get this code from this forum
ChX = GetUserDRO(1200)
ChY = GetUserDRO(1201)
ChZ = GetUserDRO(1202)
Swposx = GetUserDRO(1203)
Swposy = GetUserDRO(1204)
SwError = GetUserDro(1205)
CurrentFeed = GetOemDRO(818)
If GetOemLed (23) Then DoOemButton (119) 'Turn soft limits off
Code "G20" 'Set to inch units
Code "G53 G00 Z" &ChZ 'Move the tool all the way up
While IsMoving()
Wend
ZOld = Getdro(2)
Code "G53 G00 X" &Swposx & "Y" &Swposy 'Move to the switch position
While IsMoving()
Wend
MsgBox ("Jog Z axis down close to switch then hit Cycle Start to resume")
SystemWaitFor (Start) 'Pause macro to jog the Z axis close to the switch
Code "G31 Z-7 F10" 'Move Z down until switch is triggered
While IsMoving()
Wend
Code "G4 P0.1"
HitOld = GetVar(2002) 'Get the position where the switch was triggered
Code "G53 G00 Z" &ChZ 'Z move all way up
Code "G53 G00 X" &ChX & "Y" &ChY 'Move to change tool position
While IsMoving()
Wend
MsgBox ("Insert the new tool")
Code "G53 G00 X" &Swposx & "Y" &Swposy 'Move to the switch position
While IsMoving()
Wend
MsgBox ("Jog Z axis down close to switch then hit Cycle Start to resume")
SystemWaitFor (Start) 'Pause macro to jog the Z axis close to the switch
Code "G31 Z-7 F10" 'Z move down until switch is triggered
While IsMoving()
Wend
Code "G4 P0.1"
HitNew = GetVar(2002) 'Get the position where the switch was triggered
Code "F" &CurrentFeed
Diff = HitOld - HitNew
DiffABS =Abs(Diff)
If DiffABS=0 Then
Code "G53 G00 Z" &ChZ
Code "G53 X0Y0"
While Ismoving()
Wend
DoOemButton (119) 'Turn soft limits on
Code "(New tool is now ready for use)"
Exit Sub
End If
ZNew=0
If HitOld < HitNew Then ZNew = ZOld - DiffABS :A=1
If HitOld > HitNew Then ZNew = ZOld + DiffABS :A=2
Code "G53 G00 Z" &ChZ
While IsMoving()
Wend
Call setdro(2,ZNew - SwError)
Code "G53 X0Y0"
While Ismoving()
Wend
DoOemButton (119) 'Turn soft limits on
Code "(New tool is now ready for use)"
End