'ToolChange Macro for YUSA Rev.2010.9.6 '設定値 Const ToolChangeZ = "0" 'ツールチェンジを行うZ軸高さ(ABS) Const AfterZ = "20" 'ツールチェンジ後に復帰する高さ Const UseAfterZ = 1 '0=AfterZ値は使わず開始前刃先高さ 1=AfterZ値(WORK#1) 2=AfterZ(ABS) Const TimeOut = 10 'チェンジ動作を待つ時間 Const SpindleStartCommand = "M3" 'スピンドル回転開始コマンド Const DebugMode = False 'デバックモード使用するしない Const UseSerial = False 'シリアルポートで使用するしない(しない場合OUTPUT3-6) Const ToolMax = 4 '最大ツール番号 '定数 Const OEMTRIG1 = 29 '各種ピン(Mach3では定義済み) Const OUTPUT3 = 9 Const OUTPUT4 = 11 'Mach3では10-12の筈 Const OUTPUT5 = 12 '何故かMach2ではズレている模様 Const OUTPUT6 = 13 'ダマされた Const STOPBTN = 1003 Call Main '実行開始Mach3では自動 Sub Main() tool = GetSelectedTool() CurrentZ=GetToolChangeStart( 2 ) - ToolLengthOffset() 'ツール補正OFF Call ExCode( "G49" ) 'ツール番号チェック If (tool >= 1) and (tool =< ToolMax) Then '範囲内 Message "Now Moving to Tool Change Position." & SS Call ExCode( "G53G90G00Z" & ToolChangeZ ) Else '範囲外か0 'リファレンスツール(0)にセットし、ツールオフセット0、ツールチェンジ位置で待機終了 SetCurrentTool( 0 ) Message "*Tool # is Out of range. Will Move to Tool Change Position and Suspend.*" Call ExCode( "G53G90G00Z" & ToolChangeZ ) DoOEMButton( STOPBTN ) Exit Sub End If Call SendTool( Tool ) Message "Now Progress, Change to Tool #" & Tool If WaitForTRIG(Timeout) Then '交換正常終了 SetCurrentTool( tool ) 'ツール補正ON Call ExCode ("H" & tool & "G43") Message "Tool #" & Tool & " Selected" '完了位置へ Zpos="G54G90G00Z" Select Case UseAfterZ Case 0 Zpos = Zpos & CurrentZ Case 1 Zpos = Zpos & AfterZ Case 2 Zpos = "G53G90G00Z" & AfterZ End Select Call ExCode ( Zpos ) If GetParam( "SpindleSpeed" )<>0 then Call ExCode( SpindleStartCommand ) End If Else '交換確認できず Message "*Tool Change Failed,Because TimeOut.*" DoOEMButton( STOPBTN ) End If End Sub Function ExCode( strGcode ) 'コード実行 Call Code( strGcode ) While IsMoving() Wend End Function Function WaitForTRIG( intTimeout ) 'トリガ検出 inTime = Now() bolWait = False Do While DateDiff("s",inTime,Now()) < intTimeout 'TimeOutDetect code Here If IsActive( OEMTRIG1 ) 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 ) 'ツール番号に応じたピンをアクティブに Call PinDeactive 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