'************************************* 'M6Start.m1a v.1 by Corey Renner 'Variables: CurrentTool=GetCurrentTool() NewTool=GetSelectedTool() '************************************* Sub Main() 'This stuff is wrong************** If CurrentTool=0 Then 'Exit with error ATC not homed MsgBox ("ERROR: ATC Not Homed") Beep Code "M00" Exit Sub 'This Line is a problem, what should be here to exit the Macro?*************** End If If CurrentTool=NewTool Then 'Exit if correct tool is already loaded MsgBox ("No Toolchange Required") Exit Sub 'This Line is a problem, what should be here to exit the Macro?*************** End If 'Up to here. Everything below is fine.************* ActivateSignal(Output12) 'Deploy Changer Cylinder While Not IsActive(OEMTRIG3) 'Changer Deployed Switch sleep(100) Wend ActivateSignal(Output13) 'Slide In Cylinder While Not IsActive(OEMTRIG5) 'Slide In Switch sleep(100) Wend ActivateSignal(Output14) 'Drawbar Release and Proprod While Not IsActive(OEMTRIG6) 'Drawbar Released sleep(100) Wend ActivateSignal(Output15) 'Toolout Cylinder While Not IsActive(OEMTRIG8) 'Tool out from Spindle sleep(100) Wend '************************************************ 'carousel rotation stuff FwdIndex=CurrentTool FwdStep=0 While FwdIndex<>NewTool FwdStep=FwdStep+1 FwdIndex=FwdIndex+1 If FwdIndex>12 Then FwdIndex=1 End If Wend RevStep=12-FwdStep If FwdStep<=6 Then CarouselFWD (FwdStep) Else CarouselREV (RevStep) End If '************************************************ DeActivateSignal(Output15) 'Tool back into spindle 'ActivateSignal(Output16) 'Airblast on While Not IsActive(OEMTRIG7) 'Tool back in spindle sleep(100) Wend 'DeActivateSignal(Output16) 'Airblast off DeActivateSignal(Output14) 'Drawbar Grabs While Not IsActive(OEMTRIG6) 'Drawbar has grabbed sleep(100) Wend DeActivateSignal(Output13) 'Slide Out While Not IsActive(OEMTRIG4) 'Slide is Out sleep(100) Wend DeActivateSignal(Output12) 'ATC Retract While Not IsActive(OEMTRIG2) 'ATC Retracted sleep(100) Wend DoButton(24)'Home Z-axis to release prop-rod and correct error SetCurrentTool (NewTool) End Sub '///Functions/// Function CarouselFWD(ByVal FwdStep As Integer) As Integer ActivateSignal(Output17) 'Start Motor in FWD Direction For X=1 To FwdStep While IsActive(OEMTRIG9) sleep(100) Wend While Not IsActive(OEMTRIG9) sleep(100) Wend Next X DeActivateSignal(Output17) End Function Function CarouselREV(ByVal RevStep As Integer) As Integer ActivateSignal(Output18) 'Start Motor in REV Direction For X=1 to RevStep While IsActive(OEMTRIG9) sleep(100) Wend While Not IsActive(OEMTRIG9) sleep(100) Wend Next X DeActivateSignal(Output18) End Function