'ToolChange Macro Test Const ToolChangeZ = "200" 'ツールチェンジを行うZ軸高さ Const AfterZ = "0" 'ツールチェンジ後に復帰する高さ Const UseAfterZ = False 'AfterZ値を使用するしない(しない場合はツールチェンジ開始前の高さ) Const TimeOut = 10 'チェンジ動作を待つ時間 Const SpindleStartCommand = "M3" 'スピンドル回転開始コマンド Const DebugMode = False 'デバックモード使用するしない Const UseSerial = False 'シリアルポートで使用するしない(しない場合OUTPUT3-6) Const Trigger = 29 '動作完了通知ピン Const OUTPUT3 = 9 Const OUTPUT4 = 11 Const OUTPUT5 = 12 Const OUTPUT6 = 13 Call Main Sub Main() tool = GetSelectedTool() CurrentZ=GetToolChangeStart( 2 ) - ToolLengthOffset() Call Code( "G49" ) Call Code( "G90G00Z" & ToolChangeZ ) Message "Now Moving to Tool Change Position." Call WaitForMove Message "Now Progress, Change to Tool #" & Tool Call SendTool( Tool ) If WaitForTRIG(Timeout) Then SetCurrentTool( tool ) Call Code ("H" & tool & "G43") Message "Tool #" & Tool & " Selected" If UseAfterZ Then Zpos=AfterZ Else Zpos=CurrentZ End If Call Code ( "G00Z" & Zpos ) Call WaitForMove Call Code( SpindleStartCommand ) Else Message "Tool Change Failed,Because TimeOut." DoOEMButton( 1003 ) End If End Sub Function WaitForMove() While IsMoving() Wend End Function Function WaitForTRIG( intTimeout ) inTime = Now() bolWait = False Do While DateDiff("s",inTime,Now()) < intTimeout 'TimeOutDetect code Here If IsActive( Trigger ) Or DebugMode Then bolWait=True Exit Do End If Loop WaitForTRIG = bolWait End Function Function WaitSeconds( intSeconds ) inTime = Now() Do While DateDiff("s",inTime,Now()) < intSeconds Loop End Function Function SendTool( intTool ) If UseSerial Then Call SendSerial ("Tool#" & intTool) Else Call SendPin ( intTool ) End If End Function Function SendPin( intTool ) Select Case intTool Case 1 ActivateSignal( OUTPUT3 ) Case 2 ActivateSignal( OUTPUT4 ) Case 3 ActivateSignal( OUTPUT5 ) Case 4 ActivateSignal( OUTPUT6 ) Case Else '...... End Select Call WaitSeconds( 3 ) Call PinDeactive End Function Function PinDeactive() DeActivateSignal( OUTPUT3 ) DeActivateSignal( OUTPUT4 ) DeActivateSignal( OUTPUT5 ) DeActivateSignal( OUTPUT6 ) End Function