oh sh**t, missed that we are on a CSMIO Controller, sorry.
here the modified code:
OldTool = GetCurrentTool()
Tool = GetSelectedTool()
MaxToolNum = 4 'Max number of tools for the changer
debug = true
If debug = true Then
Message "OldTool: " & OldTool & " NewTool: " & Tool
Sleep(200)
End If
If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If
While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
Call StartTool
While NewTool <> Tool
Call CheckPins
While IsMoving()
Wend
Wend
Call StopTool
SetCurrentTool(NewTool)
'//// Subroutines /////////
Sub StartTool
ActivateSignal(Output8)
If debug = true Then
Message "Output8 On"
Sleep(200)
End If
'Code "G4 P4.0" 'Wait for the tool to rotate past the sensor
While IsMoving()
Wend
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
If debug = true Then
Message "NewTool= " & NewTool
Sleep(200)
End If
End Sub
Sub Stoptool
DeActivateSignal(Output8)
If debug = true Then
Message "Output8 Off"
Sleep(200)
End If
While IsMoving()
Wend
ActivateSignal(Output9)
If debug = true Then
Message "Output9 On"
Sleep(200)
End If
Code "G4 P1.0" 'Wait for the tool to rotate onto ratchet stop
While IsMoving()
Wend
DeActivateSignal(Output9)
If debug = true Then
Message "Output9 Off"
Sleep(200)
End If
While IsMoving()
Wend
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