Hello.
Here is my code. It is connected trough csmio IO module , module nr0 (register 100).
'------------------------------------------------------------------------------ NINO_version_0
' CS-Lab s.c. - Auto toolchanger for lathe (rotary type of ATC)
' (C) 2011
' v1.2 - 2011-11-05
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' CONFIG
'------------------------------------------------------------------------------
Const OpenSensDelay		= 800	' Time Delay [ms] after ATC unlock
Const TimeLock			= 1000 	' ATC locking time delay
Const TOOLCOUNT			= 6 	' max Tool #
' Actual ATC position inputs (CSMIO-IP inputs)
Const InT1 = 0
Const InT2 = 1
Const InT3 = 2
Const InT4 = 3
Const InT5 = 4
Const InT6 = 5
' Const InT7 = 
' Const InT8 = 
' ATC sensors inputs
Const InOpenSensor		= 6	' ATC unlocked (rotating)
Const InCloseSensor		= 7	' ATC locked - safe
' digital outputs for ATC control (CSMIO outputs)
Const OutRun			= 0		' unlock and rotate
Const OutLock			= 1		' stop rotation and lock at current position
'------------------------------------------------------------------------------
' program variables - don't modify
'------------------------------------------------------------------------------
Dim ToolNew, ToolOld, ToolSlot As Integer
Dim ToolRdy As Boolean
Dim ATC_CloseRetry
Dim InToolSens(TOOLCOUNT)
'------------------------------------------------------------------------------
  ' MACRO START
'------------------------------------------------------------------------------
	if(GetOEMLed(800)) Then
		Message("System jest w trybie ESTOP - WYMIANA PRZERWANA")
		Sleep(150)
		WaitForMove
		End
	End If
  	SetUserLED(1001, 1) ' User LED - toolchange in progress
  	
  	InToolSens(0) = InT1
  	InToolSens(1) = InT2
  	InToolSens(2) = InT3
  	InToolSens(3) = InT4
  	InToolSens(4) = InT5
  	InToolSens(5) = InT6
  	InToolSens(6) = InT7
  	InToolSens(7) = InT8
	' Get actual tool # and new tool #
	ToolOld = GetCurrentTool()
	ToolNew = GetSelectedTool()
	' little trick for double slots ATC
	If(ToolNew >= 10) Then
		ToolSlot = ToolNew - 10
	Else
		ToolSlot = ToolNew
	End If
	
	If(ToolOld >= 10) Then
		ToolOld = ToolOld - 10
	End If
	
	' The same position - no need to move
	If (ToolSlot = ToolOld) Then
		SetCurrentTool( ToolNew )
		Message("ATC is on position "& ToolSlot & " and new tool is " & ToolNew)
		WaitForMove
		SetUserLED(1001, 0)
		End
	End If
	
	If (ToolSlot > TOOLCOUNT) Then
		SetCurrentTool( ToolOld )
		SetUserLED(1001, 0)
		DoOEMButton(1003)
		DoOEMButton(1002)
		Sleep(150)
		Message("There is no tool T" & ToolNew & " in ATC")
		Sleep(150)
		End
	End If
	
	
	' T0 is a fake tool, no need to change
	If (ToolSlot = 0) Then
		ToolNew = 0
		SetCurrentTool( ToolNew )
		Message("Za³adowano narzêdzie nr: " & ToolNew)
		WaitForMove
		SetUserLED(1001, 0)
		End
	End If
	
	' unlock and rotate ATC
	RunATC
	Sleep( OpenSensDelay )
	' check ATC open sensor
	If (Not GetCsmioIn(InOpenSensor)) Then
		LockATC
		SetCurrentTool( 0 )
		SetUserLED(1001, 0)
		DoOEMButton(1021)
		DoOEMButton(1002)
		Sleep(150)
		Message("ATC locked - toolchange failed.")
		Sleep(150)
		End
	End If
	
	' wait to ATC will be on the desired position
	ToolRdy = false
	While(Not ToolRdy)
		If(GetCsmioIn((InToolSens(ToolSlot - 1)))) Then
			ToolRdy = true
		End If
	Wend
	
	
	' stop rotation and lock ATC
	LockATC
	ATC_CloseRetry = 0
	' Check lock sensor, retry lock if needed
	While(Not GetCsmioIn(InCloseSensor) And ATC_CloseRetry < 4)
		LockATC
		ATC_CloseRetry = ATC_CloseRetry + 1
	Wend
	
	' double check for succesful ATC lock
	If (Not GetCsmioIn(InCloseSensor)) Then
		SetCurrentTool( 0 )
		SetUserLED(1001, 0)
		DoOEMButton(1021)
		DoOEMButton(1002)
		Sleep(150)
		Message("ATC lock alert. Check ATC.")
		Sleep(150)
		End
	End If
  
	SetCurrentTool( ToolNew )
	Message("Succesful loaded tool T" & ToolNew)
	Sleep(150)
	WaitForMove
	SetUserLED(1001, 0)
	End
' -----------------------------------------------------------------------------
Public Function GetCsmioIn (n As Integer) As Boolean
	Dim reg As Integer
	
	If(n < 16) Then
		reg = 100
	Else
		reg = 101
		n = n - 16
	End If
	
	If(GetInBit(reg, n)) Then
		GetCsmioIn = true
	Else
		GetCsmioIn = false
	End If
	Exit Function
End Function 
' -----------------------------------------------------------------------------
Sub RunATC ()
	Call SetCsmioOut(OutLock, false)
	Sleep(150)
	Call SetCsmioOut(OutRun, true)
	Sleep(150)
End Sub
' -----------------------------------------------------------------------------
Sub LockATC ()
	Call SetCsmioOut(OutRun, false)
	Sleep(150)
	Call SetCsmioOut(OutLock, true)
	Sleep(TimeLock)
	Call SetCsmioOut(OutLock, false)
	Sleep(150)
End Sub
' -----------------------------------------------------------------------------
Public Sub SetCsmioOut (ByVal n As Integer, ByVal state As Boolean)
	If(state) Then
		SetOutBit(100, n)
	Else
		ResetOutBit(100, n)
	End If
End Sub
' -----------------------------------------------------------------------------
Sub WaitForMove ()
	While IsMoving() 
		Sleep(15) 
	Wend
End Sub                                                  
Greetings Nino