 


'Unit toolpost;

'{toolpost unit for Mach3
'{Provides drivers to control the tool post on the Denford ORAC Lathe}
'{Attached to $278, pin 14 low starts toolpost to revolve, pin 15 }
'{ is a 'busy' bit, pins 11, 12, & 13 are data bits indicating which}
'{ tool is presented pin 11 being inverted}

'{Pin 14 going low starts the cycle, the program checks pins 11,12,&13}
'{until the correct tool is presented, then raises pin 14. This makes }
'{the toolpost reverse onto its location rachet. Program waits until
'{busy bit clears}

'{start toolpost  forcing pin 14 low}
'{stop toolpost   forcing pin 14 high}
'------------------------------------------------------------------
'<USES>

'OEM Trigger #1 = pin 11
'OEM Trigger #2 = pin 12
'OEM Trigger #3 = pin 13
'OEM Trigger #4 = pin 15
'OEM Output  #1 = pin 14
Option Explicit


Dim TOOL,OldTool,SelectedTool,MaxToolNum,T,TSET,C
Dim PIN_A,PIN_B,PIN_C,PINVALUE,XPOS

'Tool Changer Macro 

SYSTEMWAITFOR (32)

Oldtool = GetDro (5) 'C DRO

'OldTool = GetCurrentTool()
Tool = GetSelectedTool()


SelectedTool =0
MaxToolNum = 8      'Max number off tools for the changer


' do not allow tool number greater than number of turret positions
While tool > MaxToolNum Or tool < 1
Tool = Question ("Invalid Tool Requested, New Tool Number?")
Wend


If Tool = OldTool Then
Message ("Tool already selected") 
Exit Sub
End If


'XPOS = GETDRO (1283)

'If xpos < -2 Then CODE "G0 X50"

'While ISMOVING ()
'WEND

ActivateSignal(Output1) 

T = Second(Now)
TSET = T + 1.5      ' ADD A 0.5 SEC WAIT
Do
T = Second(Now)
Loop Until T > TSET

Do 
'OEM Trigger #1
Pin_A = IsActive (29)'INNER
'OEM Trigger #2
Pin_B = IsActive (30)'MIDDLE   TOOL CODE WHEEL TRACKS
'OEM Trigger #3
Pin_C = IsActive (31)'OUTER

PinValue = 0

If Pin_A Then PinValue = PinValue + 1
If Pin_B Then PinValue = PinValue + 2
If Pin_C Then PinValue = PinValue + 4

Select Case PinValue
Case = 7
SelectedTool = 6
Case = 6
SelectedTool = 7
Case = 5
SelectedTool = 3
Case = 4
SelectedTool = 2
Case = 3
SelectedTool = 5
Case = 2
SelectedTool = 8
Case = 1
SelectedTool = 4
Case = 0
SelectedTool = 1
End Select

For c = 1 To 2000  '2000
Next

Loop Until SelectedTool = Tool


deActivateSignal(Output1) 

Tool = SelectedTool

'Check Busy Flag
Do While IsActive(32) = false
Loop


'Send current tool to memory (C dro)
SetDro (5,tool)

Message ("Selected Tool" & tool)
SetCurrentTool(Tool)




End



           