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
Properly read the pause button example
This code implements the pause button during moving. It also debounces the
pause button which is usually necessary.
dim xpos
dim ypos
dim zpos
dim moving 'moving... 0=no, 1=yes, 2=paused
dim startswitch
dim pauseswitch
dim killflag
dim machinepaused
mainprogram()
public function mainprogram()
startswitch=7
pauseswitch=3
xpos=10
ypos=10
speed(100)
accel(5)
SMOVETO xpos,ypos
moving = 1
WHILE (NOT COMPLETEDMOVE)
CALL checkpause
WEND
moving = 0
end function 'this is the end of the small program. Anything below this is a check function.
public function checkpause()
dim incr
for incr=0 to 20
IF IOIN(pauseswitch)=FALSE THEN
'MACHINE IS PAUSED
ELSE
machinepaused=FALSE
EXIT FUNCTION
END IF
next 'incr
machinepaused=TRUE
paused()
end function
public function paused()
dim incr
halt "YXZ",false
moving=2
messagetop "Paused",2
do
IF IOIN (startswitch) = TRUE THEN
incr=incr+1
else
incr=0
end if
if incr>20 then
unpause()
exit do
END IF
loop
end function
public function unpause()
messagetop "Unpaused",2
machinepaused=FALSE
if moving=2 then
SMOVETO xpos,ypos
moving=1
end if
end function
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
Toggling an output while moving without stopping
This example shows how to toggle an output during a move without the move
slowing down.
SMOVETO 10
DO
IF POS("X")>2 THEN
IOOUT "0","1"
MESSAGETOP "OUTPUT 0 ON","2"
EXIT DO
END IF
IF ACTIVE=FALSE THEN EXIT DO
LOOP
DO
IF POS("X")>8 THEN
IOOUT "0","0"
MESSAGETOP "OUTPUT 0 OFF","2"
EXIT DO
END IF
IF ACTIVE=FALSE THEN EXIT DO
LOOP
DO
IF COMPLETEDMOVE()=TRUE THEN EXIT DO
LOOP
|