

    'CINCINNATI-750 MACH3 CNC SOFTWARE RETROFIT
   
   Dim OLDTOOL,NewTool,Slot,HomeSensor,Count As Integer 
    
  OldTool=GetCurrentTool()
  NewTool=GetSelectedTool()
  Slot=GetUserDro(1220)
  
  HomeSensor=(GetOEMTRIG10)
  Count=(GetOEMTRIG11)
  
  
  TIS1=GETOEMDRO(1201)       'TOOL IN SLOT
  TIS2=GetOemDro(1202)
  TIS3=GetOemDro(1203)
  TIS4=GetOemDro(1204)
  TIS5=GetOemDro(1205)
  TIS6=GetOemDro(1206)
  TIS7=GetOemDro(1207)
  TIS8=GetOemDro(1208)
  TIS9=GetOemDro(1209)
  TIS10=GetOemDro(1210)
  TIS11=GetOemDro(1211)
  TIS12=GetOemDro(1212)
  TIS13=GetOemDro(1213)
  TIS14=GetOemDro(1214)
  TIS15=GetOemDro(1215)
  TIS16=GetOemDro(1216)
  TIS17=GetOemDro(1217)
  TIS18=GetOemDro(1218)
  TIS19=GetOemDro(1219)
  TIS20=GetOemDro(1230)
  TIS21=GetOemDro(1231)
  TIS22=GetOemDro(1232)
  TIS23=GetOemDro(1233)
  TIS24=GetOemDro(1234)
  
  
  
   If NewTool=OldTool Then
     MsgBox "SAME TOOL"
       Exit Sub
   
   
  

   End If
  If NewTool=TIS1 Or NewTool=TIS2 Or NewTool=TIS3 Or NewTool=TIS4 Or NewTool=TIS5 Or NewTool=TIS6 _ 
  Or NewTool=TIS7 Or NewTool=TIS8 Or NewTool=TIS9 Or NewTool=TIS10 Or NewTool=TIS11 Or NewTool=TIS12 _ 
  Or NewTool=TIS13 Or NewTool=TIS14 Or NewTool=TIS15 Or NewTool=TIS16 Or Newtool=TIS17 Or NewTool=TIS18 _ 
  Or NewTool=TIS19 Or NewTool=TIS20 Or NewTool=TIS21 Or NewTool=TIS22 Or NewTool=TIS23 Or NewTool=TIS24 Then  
    
    CODE "M19"
    GoToSafeZ()
  While IsMoving
  Wend
   Message "TOOL IN CAROUSEL"
  ActivateSignal (Output13)'move tool arm to spindle on
  While IsActive (OEMTRIG9)=0
  Sleep (300)
  Wend
 DeActivateSignal (Output13)'move tool arm to spindle off
 ActivateSignal (Output9)'extend tool arm
 While IsActive (OEMTRIG3)=0
 Sleep (300)
 Wend
 ActivateSignal (Output11)'PBD unlock
 While IsActive (OEMTRIG7)=0
 Sleep (300)
 Wend
 Code "M7"
 ActivateSignal (Output10)'tool arm down
 While IsActive (OEMTRIG5)=0
 Sleep (300)
 Wend
 ActivateSignal (Output12)'move tool arm to carousel on
 While IsActive (OEMTRIG8)=0
 Sleep (300)
 Wend
 Code "M9"
 DeActivateSignal (Output10)'tool arm up
 While IsActive (OEMTRIG4)=0
 Sleep (1000)
 Wend
 DeActivatesignal (Output9)'tool arm retract
 DeActivateSignal (Output12)'move tool arm to carousel off
 DeActivateSignal (Output11)'PBD lock
  Message "Spindle Is Empty"
  SetUserDro(1224,0)
  Sleep (2000)
 
  'Sequence to determine the least travel to move for TC, CW or CCW
'atp = Actual tool position, rtp = Requested tool positon
Sub LeastTravel()
   NewTool = GetSelectedTool()
   OldTool = GetCurrentTool()
   NTool =24 ' Number of tools changer holds
   CWPos = GetSelectedTool() - GetCurrentTool() ' Assume a CW move
   If CWPos < 0 Then ' CWPos < 0 ==> rtp < atp
      CWPos = CWPos + NTool
   End If
   CCWPos = NTool - CWPos
   If CWPos < CCWPos Then
      Call CW()
   Else
      Call CCW()
   End If
End Sub

Function CW()'Rotation CW
   Dim x As Integer
   Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
   CTPos=0
   ActivateSignal(OUTPUT16)'UnLock Pin
   While IsActive (OEMTRIG12)=1
   Wend
   ActivateSignal(OUTPUT15)'Turns Carousel CW
   Sleep(50)

   For x=1 To CWPos
           While IsActive(OEMTRIG11)=0
      Sleep(100)
      Wend
           While IsActive(OEMTRIG11)=1
      Sleep(100)
      Wend
        Next x
    CTPos=x
   DeactivateSignal(OUTPUT15)
   Deactivatesignal(OUTPUT16)
End Function

Function CCW()'Rotation CCW
   Dim y As Integer
   Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
   CTPos=0
   ActivateSignal(Output16)'UnLock Pin
   While IsActive (OEMTRIG12)=1
   Wend
   Activatesignal(OUTPUT14)'Turn Carousel CCW
   
    Sleep(50)
   
     For y=1 To CCWPos
           While IsActive(OEMTRIG11)=0
      Sleep(100)
      Wend
           While IsActive(OEMTRIG11)=1
      Sleep(100)
      Wend
        Next y
   CTPos=y
   DeactivateSignal(OUTPUT14)
   Deactivatesignal(OUTPUT16)
End Function
  
  
   
   ActivateSignal(Output9)
   While IsActive(OEMTRIG3)=0
   Sleep (300)
   Wend
   ActivateSignal(Output10)
   While IsActive(OEMTRIG5)=0
   Sleep (300)
   Wend
   ActivateSignal(Output13)
   While IsActive(OEMTRIG9)=0
   Sleep (300)
   Wend
   Code "M7"
   ActivateSignal(Output11)
   While IsActive(OEMTRIG7)=0
   Sleep (300)
   Wend
   DeActivateSignal(Output10)
   While IsActive(OEMTRIG4)=0
   Sleep (500)
   Wend
   Code "M9"
   DeActivateSignal(Output11)
   While IsActive(OEMTRIG6)=0
   Sleep (500)
   Wend
   DeActivateSignal(Output9)
   While IsActive(OEMTRIG3) = 1 
   Sleep (2000)
   Wend
   DeActivateSignal(Output13)
   Sleep (1000)
   ActivateSignal(Output12)
   While IsActive(OEMTRIG8)=0
   Wend 
   DeActivateSignal(Output12)

   
   
   End If
  
  SetUserDro(1224,NewTool)
  SetUserDro(1220,NewTool)
  SetCurrentTool(NewTool)
  DeActivateSignal(Output17)
  While IsMoving
  Wend
  Exit Sub
  
  'End If
  'If NewTool<>Slot Then 
  'CODE "M19"
  'While IsMoving
  'Wend
  'MsgBox "TOOL NOT IN CAROUSEL"
  
  'End If
  
  'SetUserDro(1224,NewTool)
  'SetCurrentTool(NewTool)
  'DeActivateSignal(Output17)
  'While IsMoving
  ''Wend
  'Exit Sub
  
  
  
  
  
  
 End 
  
  
  
  
  
  
                                                                          