' VBscript to log positions from a graphic tablet 
' tablet input from the modbus input registers
' register 0 is X position	Tablet.brn loads the UserDRO(1010) with tablet value
' register 1 is Y position	Tablet.brn loads the UserDRO(1011) with tablet value
' register 2 is button pressed	Tablet.brn loads sets the Boolean Led(1200)

y = GetUserDRO(1022)		'Current number of cut stored in UserDRO(1022)	increments previous value 
z = GetUserDRO(1023)		'Group number stored in UserDRO(1023)  entered manually at begining of work sesion		
OpenTeachFile  "Group" & z & "-" & y & ".tap"	'3-12.tap
code "G20"
code "G53 G90 G40"
code "F1"
code "G00 Z1.0000"
code "F45"


For x = 1 To 100		'up to 100 points logable---really used it as a way to get out of the second loop		 
'IT LOCKS UP WHEN I STEP TO THE NEXT WHILE ON MY COMPUTER IN THE SHOP BUT NOT ON 2 COMPUTERS IN THE HOUSE??
While getUserLed(1200)
Wend 				'wait here for the "tablet.brn" to see I've pressed the button on the tablet
 
 
Do While Not GetUserLed(1200)	'wait a while here so we don't log more than one point

 count = count + 1		'increment delay counter
 
If count > 20000 Then
  Exit Do
End If
Loop

 
TabletXaxisPos = GetUserDRO(1010)	' get the tablet position
TabletYaxisPos = GetUserDRO(1011) 

If TabletXaxisPos > 11.5 Then		' if we choose a position > than 11.5 in x we stop logging points
   x = 101				' set x to get out of loop
   code "M05"				' if were quitting we stop the cut
   Else
       If x = 1 Then
          Code "G01 X"&TabletXaxisPos & " Y"& TabletYaxisPos	'go to first point and turn on plasma cutter
          code "M03"
       Else
          Code "G01 X"&TabletXaxisPos & " Y"& TabletYaxisPos	'log each addition point
       End If 				' end of which cut we're on
End If					' end of if were going to quit cutting
 count = 0				' reset button press delay 
Next x					' return for next point

 
code "G00 Z6.0000"			' all done
code "M30"				
y = y + 1
SetUserDRO(1022,y)			'tell the cut counter which cut we're on
 	
CloseTeachFile()
Call LoadTeachFile()
                   