From TechnoDocs
Revision as of 06:32, 5 August 2011 by Jbeck (Talk | contribs) (Created page with "These examples were written in SAC. To run an example, copy the code and paste it into a file called "example.sac". Press File in the Control Software to load the file, and R...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

These examples were written in SAC. To run an example, copy the code and paste it into a file called "example.sac". Press File in the Control Software to load the file, and Run to execute it. In the two examples that loop, pressing the Estop will disable the machine and cause the SAC script to exit.

Gcode and Offsets Example

This example shows how to load an offset from the Offsets table in the Control Software, and run a gcode file.

'-------------------Home Machine---------------
Home "Z"
Home "X"
Home "Y"

'----------------Load Origin 1----------------------
retrieveorigin 1

'-------Set spindle,Set Speed&Accel. Move to Offset.-----------
routerauto
accel 25
speed 800
moveto 0,0

'------------------Load File------------------
gcodefile("c:\filelocation\filename1.ncd")
gcodepreprocess
gcoderun

'------------------Load Offset2------------------
retrieveorigin 2

'------------------Load File------------------
gcodefile("c:\filelocation\filename2.ncd)
gcodepreprocess
gcoderun

routeroff


Input/Output Checking Example

This example will check the status of input 14, and will exit when the input goes high.

IOOUT "0","1"
DELAY 2
IOOUT "0","0"

MESSAGE "Waiting for input..."
DO
	' Check the status of input 14 ("Input 6" in Diagnostics)
	' See sac_diagnostics.gif below for a handy diagram.
	IF IOIN(14) = TRUE THEN
		EXIT DO
	END IF
	
	' Check to make sure the machine is enabled
	if active() = false then
		exit do
	end if
LOOP

Sac diagnostics.gif


Input/Output With G-Code File Execution

This example is a bit more involved. It runs a gcode file every time the Pause button has been pressed. It also turns on and off an output, and writes a message to the interface.

' This example loads a gcode file
' and runs it every time the user
' presses the Pause button on the
' remote start/stop box.
'
' Any digital input would work, to 
' start the program. We use Pause
' because it's convinent.
'
' Zero the machine where you want
' the gcode to start. Press the
' e-stop to exit the software.
' Remember to re-enable the machine
' before attempting to re-run the
' script. To do so, jog the machine
' and answer Yes to re-enable.
'


' Loads the gcode file
gcodefile "C:\Program Files\Techno CNC Interface v1.421\examples\2box.nc"

' Preprocesses the gcode file
gcodepreprocess

' Loop until the user presses the e-stop.
do

  messagetop "Waiting for Pause press...", 2

  do

    ' Waits for the pause button to be pressed on the 
    ' remote box. The pause button is normally closed,
    ' so we have to read "false" to see a press.
    if ioin(3) = false then 
      exit do
    end if
    
    ' Check to make sure the machine is enabled. Pressing
    ' the e-stop will disable the machine, exiting this loop.
    if active() = false then 
      exit do
    end if

  loop

  ' Check to make sure the machine is enabled. Pressing
  ' the e-stop will disable the machine, exiting this loop.
  if active() = false then 
    exit do
  end if

  messagetop "Running gcode...", 2

  ' Run the gcode file loaded at the start of this script.
  gcoderun

  messagetop "Turning on output 1...", 2

  ' Turns out 1 ON
  ioout "1","1"

  ' Waits 2 Seconds
  Delay 2

  ' Turns out 1 OFF
  ioout "1","0"

loop