1331
VB and the development of wizards / Re: macro for 4 slot tool change hep
« on: April 26, 2019, 05:06:16 AM »Code: [Select]
Public NewTool As Integer
Sub Main
'//Declarations
Dim StartTime, ActTime As Single
MaxToolNum = 4 'Max number of tools for the changer
OldTool = GetCurrentTool()
Tool = GetSelectedTool()
If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If
If Tool > MaxToolNum Then
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
End If
doagain:
Call StartTool
While NewTool <> Tool
Call CheckPins
Wend
Call StopTool
're check
Call CheckPins
If NewTool <> Tool Then
GoTo doagain
End If
SetCurrentTool(NewTool)
End Sub
'//// Subroutines /////////
Sub StartTool
ActivateSignal(Output8)
End Sub
Sub CheckPins
If GetCsmioIn(91,6) = True Then
NewTool = 1
End If
If GetCsmioIn(91,5) = True Then
NewTool = 2
End If
If GetCsmioIn(91,4) = True Then
NewTool = 3
End If
If GetCsmioIn(91,3) = True Then
NewTool = 4
End If
End Sub
Sub Stoptool
DeActivateSignal(Output8)
ActivateSignal(Output9)
'wait for input 23 or timeout
StartTime = Timer
While GetCsmioIn(91,7) = False
Sleep(20)
ActTime = Timer
If ActTime > StartTime + 3 Then
DeActivateSignal(Output9)
MsgBox "Timeout Input23!!"
DoButton(3)
Sleep(300)
Exit Sub
End If
Wend
DeActivateSignal(Output9)
End Sub
'CSMIO Eingang lesen
Function GetCsmioIn (ByVal adr As Integer, ByVal n As Integer) As Boolean
If(GetInBit(adr, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
End Function