'Inputs are as follows:'''OEMTRIG1 = Encoder Bit 1'OEMTRIG2 = Encoder Bit 2'OEMTRIG3 = Encoder Bit 3'OEMTRIG4 = Encoder Bit 4'OEMTRIG5 = Parity Bit'OEMTRIG6 = Strobe1'OEMTRIG7 = Strobe2'OEMTRIG8 = Index Proximity Switch'OEMTRIG9 = Lock Proximity Switch'OEMTRIG10 = Door Switch'''Outputs are as follows:'''OUTPUT10 = Lock Solenoid'''If IsActive(OEMTRIG10) Then			'check Door state'MsgBox("Close the Door")'End If					'Read the Encoder BitsIf IsActive(OEMTRIG1) ThenBit1 = 1ElseBit1 = 0End IfIf IsActive(OEMTRIG2) ThenBit2 = 1ElseBit2 = 0End If					If IsActive(OEMTRIG3) ThenBit3 = 1ElseBit3 = 0End If					If IsActive(OEMTRIG4) ThenBit4 = 1ElseBit4 = 0End IfIf IsActive(OEMTRIG5) ThenParity = 1ElseParity = 0End IfIf IsActive(OEMTRIG6) ThenStrobe1 = 1ElseStrobe1 = 0End IfIf IsActive(OEMTRIG7) ThenStrobe2 = 1ElseStrobe2 = 0End If					'Where the hell is the turret now?If Bit1=1 And Bit2=0 And Bit3=0 And Bit4=0 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 1ElseIf Bit1=0 And Bit2=1 And Bit3=0 And Bit4=0 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 2ElseIf Bit1=1 And Bit2=1 And Bit3=0 And Bit4=0 And Parity=0 And Strobe1=1 And Strobe2=0 ThenPosition = 3ElseIf Bit1=0 And Bit2=0 And Bit3=1 And Bit4=0 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 4ElseIf Bit1=1 And Bit2=0 And Bit3=1 And Bit4=0 And Parity=0 And Strobe1=1 And Strobe2=0 ThenPosition = 5ElseIf Bit1=0 And Bit2=1 And Bit3=1 And Bit4=0 And Parity=0 And Strobe1=1 And Strobe2=0 ThenPosition = 6ElseIf Bit1=1 And Bit2=1 And Bit3=1 And Bit4=0 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 7ElseIf Bit1=0 And Bit2=0 And Bit3=0 And Bit4=1 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 8ElseMsgBox("Turret out of position")EndEnd If OldTool = PositionNewTool = GetSelectedTool()NumberOfStations = 0LockProx = 0Strobe1 = 0IndexProx = 0Rotation = 0										If NewTool < 1 ThenMsgBox("Tool Number Too Low")EndEnd IfIf NewTool > 8 ThenMsgBox("Tool Number Too High")EndEnd IfIf NewTool = OldTool Then'MsgBox("Selected Current Tool")EndEnd If					'Determine which way to turn and how many stations					If NewTool > OldTool ThenNumberOfStations = (NewTool-OldTool)ElseNumberOfStations = (OldTool-NewTool)End IfIf NumberOfStations > 4 ThenNumberOfStations = 8 - NumberOfStationsEnd IfIf NewTool = (OldTool+NumberOfStations) ThenRotation = 1ElseIf NewTool = (OldTool-NumberOfStations) ThenRotation = -1ElseIf (OldTool+NumberOfStations) > 8 ThenRotation = 1ElseIf (OldTool-NumberOfStations) < 1 ThenRotation = -1Else Rotation = 1End IfDoOemButton(138)				'Go home  	While IsMoving()			'wait for movement	sleep(100)	Wend					'to end   For I = 1 To 18					'Slow jog is needed	DoOemButton(112)			'for extra torqueNext I						'If Rotation = 1 ThenDoOemButton(310)				'Rotate Turret CCW (axis Y-)ElseDoOemButton(309)				'Rotate Turret CW  (axis Y+)End Ifsleep (500)					'Turn for .5 secDoOemButton(1003)				'Stop Motor For I = 1 To 18					'Back to Fast jog	DoOemButton(111)Next IIf Rotation = 1 ThenDoOemButton(310)				'Rotate Turret CCW (axis Y-)ElseDoOemButton(309)				'Rotate Turret CW  (axis Y+)End If   For I = 1 To NumberOfStations			'Count number of stations	While Strobe1 = 0			'Wait for Strobe1 to go high		If IsActive(OEMTRIG6) Then		Strobe1 = 1		Else		Strobe1 = 0		End If	Wend		While IsActive(OEMTRIG6)		'Look for Strobe1 to go low	Wend					'Number of Srobe1 falls =						'Number of stationsStrobe1 = 0	Next IActivateSignal(OUTPUT10)			'Energize lock solenoidWhile LockProx = 0				'Look for Lock Proximity Switch	If IsActive(OEMTRIG9) Then		'to go high	LockProx = 1	Else 	LockProx = 0	End IfWendDoOemButton(1003)				'stop motorSleep(100)					'wait for dampingFor I = 1 To 18					'slow jog	DoOemButton(112)			'for increased torqueNext IIf Rotation = 1 Then				'Reverse MotorDoOemButton(309)				'Rotate Turret CW (axis Y+)ElseDoOemButton(310)				'Rotate Turret CCW  (axis Y-)End Ifsleep (200)					'Turn for .2 secDoOemButton(1003)				'Stop MotorFor I = 1 To 18					'Fast Jog	DoOemButton(111)Next IIf Rotation = 1 Then				'Continue to Reverse MotorDoOemButton(309)				'Rotate Turret CW (axis Y+)ElseDoOemButton(310)				'Rotate Turret CCW  (axis Y-)End IfWhile IndexProx = 0				'Look for IndexProx to go high	If IsActive(OEMTRIG8) Then		'IndexProx must complete	IndexProx = 1				'OFF-ON-OFF	Else	IndexProx = 0	End IfWendWhile IsActive(OEMTRIG8)			'Look for IndexProx to go lowWendDoOemButton(1003)				'Stop motor	sleep(200)DeActivateSignal(OUTPUT10)			'De-Energize Lock Solenoid		 						'Now in positionSetCurrentTool( NewTool )					'Read the Encoder Bits					Sleep(1000)																				If IsActive(OEMTRIG1) ThenBit1 = 1ElseBit1 = 0End IfIf IsActive(OEMTRIG2) ThenBit2 = 1ElseBit2 = 0End If					If IsActive(OEMTRIG3) ThenBit3 = 1ElseBit3 = 0End If					If IsActive(OEMTRIG4) ThenBit4 = 1ElseBit4 = 0End IfIf IsActive(OEMTRIG5) ThenParity = 1ElseParity = 0End IfIf IsActive(OEMTRIG6) ThenStrobe1 = 1ElseStrobe1 = 0End IfIf IsActive(OEMTRIG7) ThenStrobe2 = 1ElseStrobe2 = 0End If					'Where the hell is the turret now?If Bit1=1 And Bit2=0 And Bit3=0 And Bit4=0 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 1ElseIf Bit1=0 And Bit2=1 And Bit3=0 And Bit4=0 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 2ElseIf Bit1=1 And Bit2=1 And Bit3=0 And Bit4=0 And Parity=0 And Strobe1=1 And Strobe2=0 ThenPosition = 3ElseIf Bit1=0 And Bit2=0 And Bit3=1 And Bit4=0 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 4ElseIf Bit1=1 And Bit2=0 And Bit3=1 And Bit4=0 And Parity=0 And Strobe1=1 And Strobe2=0 ThenPosition = 5ElseIf Bit1=0 And Bit2=1 And Bit3=1 And Bit4=0 And Parity=0 And Strobe1=1 And Strobe2=0 ThenPosition = 6ElseIf Bit1=1 And Bit2=1 And Bit3=1 And Bit4=0 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 7ElseIf Bit1=0 And Bit2=0 And Bit3=0 And Bit4=1 And Parity=1 And Strobe1=1 And Strobe2=0 ThenPosition = 8ElseMsgBox("Turret out of position")EndEnd If If IsActive(OEMTRIG6) Then			'check strobe1 state'everything checks outElseMsgBox("Turret out of position")EndEnd IfIf IsActive(OEMTRIG7) Then			'check strobe2 stateMsgBox("Turret out of position")EndEnd IfIf IsActive(OEMTRIG8) Then			'check IndexProx stateMsgBox("Turret Index Proximity Fault")EndEnd IfIf IsActive(OEMTRIG9) Then			'check LockProx stateMsgBox("Turret Lock Pin Retract Failure")EndEnd If'If IsActive(OEMTRIG10) Then			'check Door state'MsgBox("Close the Door")'End IfIf Position = GetSelectedTool() Then		'check tool = selected tool'is OKElseMsgBox("Turret not in selected position!!")EndEnd IfEnd       