881
VB and the development of wizards / Re: Emco Turn tool changer macro
« on: December 03, 2010, 04:07:06 PM »
I just fixed your errors, not sure it will do what you want but it will compile and you can at least step thru it.
Code: [Select]
'M6Start.M1s
'Input1 is an optical sensor used to count tool positions
'Input2 is from a microswitch used to determine tool 0 position
'OUTPUT3 drives the tool changer forward, de activating it allows the tool changer to rotate back against the ratchet pawl at low power and is the default
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
MaxToolNum = 6 'Max number of tools for the changer
CurrPos = OldTool
While (NewTool > MaxToolNum)
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
'there is nothing to do so we just exit
If (NewTool = OldTool) Then
Exit Sub
End If
'If OldTool is 0 that means we dont know where the tool changer is currently positioned and need to reference to the microswitch for tool 1 position.
'need to establish tool 0 position from microswitch
If (OldTool = 0) Then
While Not IsActive(INPUT2)
ActivateSignal(OUTPUT3) ' rotate tool changer forward
Wend
' Input 2 must Now be active so the microswitch has been triggered
DeActivateSignal(OUTPUT3)
CurrPos = 1
End If
If (CurrPos <> NewTool) Then
While CurrPos <> NewTool
ActivateSignal(OUTPUT3) 'start rotating forward
If Not IsActive(INPUT1) And Not IsActive(INPUT2) Then
CurrPos = CurrPos +1
If CurrPos = 7 Then
CurrPos = 1
End If
If IsActive(INPUT2) Then
CurrPos = 1
End If
If CurrPos = NewTool Then
DeActivateSignal(OUTPUT3) 'stop rotating forward, rotate backward now
CurrentTool = NewTool 'sets up the current tool variable as the start point for a future tool change
Sleep(200) 'Allow a time interval for the toolchanger to settle back against the ratchet pawl
Else
Sleep(100) 'wait for the motor to rotate past the current position then test again
End If
End If
Wend
End If