Machsupport Forum
		Mach Discussion => VB and the development of wizards => Topic started by: nso on October 18, 2015, 03:56:10 PM
		
			
			- 
				hi everyone
i need to add a macro as( time out) also i have tried to write something but that isn't worked...anyway i need to help
'ToolChange Macro For milling machine (liner type)
Sub Main()
OldTool = GetOEMDRO (1200) 'Tool In spindle DRO You must add this to your settings screen
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 ) 
z = GetToolChangeStart( 2 ) 
tool = GetSelectedTool()
NewTool = tool
'Tool Changer Macro (Bed Type)
MaxToolNum = 2      'Max number off tools for the changer
ToolDown   = -60 'Z Pos to Get or drop a tool
ToolUp     = 0   'Z Hieght to Rapid from tool to tool
If NewTool = OldTool Then 
   Exit Sub
End If
While NewTool > MaxToolNum
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
Code "G00 G53 Z" & ToolUp
While IsMoving()
Wend
Call MovePos(OldTool)
While IsMoving()
Wend
Code "G53 Z" & ToolDown
Code "G4 P.1"
While IsMoving()
Wend
Do                                                 'Start loop
ActivateSignal(Output2)                   'This is signal to activate  drawbar
If IsActive (Input1) Then Exit Do        'This is a  signal to say drawbar has released
Loop
Code "G53 Z" & ToolUp
Call MovePos(NewTool)
While IsMoving()
Wend
Code "G53 Z" & ToolDown
Code "G4 P.1"
While IsMoving()
Wend
DeActivateSignal(Output2) 'Turn Off Draw bar to Clamp the tool
Code "G4 P4.1"    'Wait for the tool to Clamp
While IsMoving()
Wend
============================================
its good but i think not enough ,i need something like this: if (input 2 ) not active after a time (10 ms) then show a (msgbox "tool isn't locked "   ) then active (emergency ) 
Do                                                 'Start loop
If IsActive (Input2)  Then  Exit Do      'This is a signal to say tool locked correctly
Loop
===========================
Code "G53 Z" & ToolUp
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )
Code "G00 X" & x & " Y" & y 'Move back to where the tool change was prompted
End Sub
Sub MovePos(ByVal ToolNumber As Integer)
Select Case ToolNumber
       Case Is = 1
         Xpos = 10
         YPos = 10
       Case Is = 2
         Xpos = 20
         YPos = 20
   
End Select
Code "G53 X" & XPos & " Y" & YPos
End Sub
Main        
			 
			
			- 
				
Lcnt = 0        ' Set loop Counter to Zero
Do   while   isactive( input2)  = false       'Start loop
Lcnt = (Lcnt+1)                                  ' Add to counter
If Lcnt >= 1000 then                           ' Check for max count, if then do
DoButton(3)
MsgBox(" Tool Change Timed Out ")       ' Notify Operator  Or use Message" Tool Changer timed out" to write to the status line
END
End if
Loop
			 
			
			- 
				thanks a million dear BR549,that was what i need exactly also worked great   :)
'ToolChange Macro For milling machine (liner type)
Sub Main()
OldTool = GetOEMDRO (1200) 'Tool In spindle DRO You must add this to your settings screen
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 ) 
z = GetToolChangeStart( 2 ) 
tool = GetSelectedTool()
NewTool = tool
'Tool Changer Macro (Bed Type)
MaxToolNum = 2      'Max number off tools for the changer
ToolDown   = -60 'Z Pos to Get or drop a tool
ToolUp     = 0   'Z Hieght to Rapid from tool to tool
If NewTool = OldTool Then 
   Exit Sub
End If
While NewTool > MaxToolNum
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
Code "G00 G53 Z" & ToolUp
While IsMoving()
Wend
Call MovePos(OldTool)
While IsMoving()
Wend
Code "G53 Z" & ToolDown
Code "G4 P.01"
While IsMoving()
Wend
=========================================
 just for make sure the input 1 worked rightly at defined time because sometime the air pressure might isn't enough  so, i tried to do something like that here but didn't work    :-\
Do                                                 'Start loop
ActivateSignal(Output2)                   'This is signal to activate your drawbar
If IsActive (Input1) Then Exit Do        'This is your  signal to say drawbar has released
Loop
=======================================
Code "G53 Z" & ToolUp
Call MovePos(NewTool)
While IsMoving()
Wend
Code "G53 Z" & ToolDown
Code "G4 P.01"
While IsMoving()
Wend
DeActivateSignal(Output2) 'Turn Off Draw bar to Clamp the tool
Code "G4 P4.01"    'Wait for the tool to Clamp
While IsMoving()
Wend
Lcnt = 0        ' Set loop Counter to Zero
Do   While   isactive( input2)  = false       'Start loop
Lcnt = (Lcnt+1)                                  ' Add to counter
If Lcnt >= 1000 Then                           ' Check for max count, if then do
DooemButton(1021)
MsgBox(" Tool Change Timed Out/ tool isn't clamped correctly")       ' Notify Operator  Or use Message" Tool Changer timed out" to write to the status line
End
End If
Loop
Code "G53 Z" & ToolUp
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )
Code "G00 X" & x & " Y" & y 'Move back to where the tool change was prompted
End Sub
Sub MovePos(ByVal ToolNumber As Integer)
Select Case ToolNumber
       Case Is = 1
         Xpos = 10
         YPos = 10
       Case Is = 2
         Xpos = 20
         YPos = 20
   
End Select
Code "G53 X" & XPos & " Y" & YPos
End Sub
Main