July 29, 2020

Alpha Release

The alpha release can be downloaded from the Github Repository. Please note that the CNC APIs are not fixed and may be changed. It has been tested on Linux and OSX (with homebrew C++ development tools installed).

Quick Reference Guide for CNC BASIC

Data Types

BOOLEAN True or False
BYTE 8 bit signed integer value
COMPLEX Complex type with double real and imaginary components
DOUBLE 64 bit double precision float
FLOAT 32 bit single precision float
INTEGER 32 bit signed integer value
LONG 64 bit signed integer value
SHORT 16 bit signed integer value
STRING Character string
VARIANT Different types at different time - used in function argument lists.


x + y Addition
x - y Subtraction
x * y Multiplication
x / y Division
x % y Modulus / Remainder
x ** y Power
-x Unary minus
x & y Bitwise AND
x | y Bitwise OR
x ^ y Bitwise Exclusive OR
~x Unary bit complement
x << y Bit shift left
x >> x Bit shift right (signed extension)
x >>> y Bit shift right (no sign extension)
x AND y Logical AND
x OR y Logical OR
NOT x Logical NOT
x = y Equality
x <> y Inequality
x >= y Greater than or equal to
x > y Greater than or equal to
x <= y Less than than or equal to
x < y Less than than


CALL subroutine(params, …) CALL Subroutine with parameters
DATA x,y,z Define list of data for READ statement
DIM X AS {type} Define variable as type
FOR I=START TO END [ STEP N ] Start of FOR loop (Integer loop values only)
END FOR End of FOR loop
FUNCTION name(arglist) AS {type} Define function
END FUNCTION End of function
IF (exp) THEN Start of IF Statement
ELSE IF (exp) THEN Multiple optional IF statements
ELSE Optional final part of IF statement
END IF End of IF Statement
INPUT “Prompt”,X INPUT Statement
PRINT “Output String” PRINT Statement
READ X [,Y …] READ next value(s) from DATA statement
UNTIL (exp) End of REPEAT UNTIL loop
RESTORE label Restore DATA pointer to label
SLEEP ms Sleep for a number of milliseconds
SUB name(arglist) Define subroutine
END SUB End of subroutine
THROW errorMessage THROW an error that can be caught by CATCH
TRY Start of TRY block
CATCH variable Catch error messages thrown within TRY block and stores in variable
END TRY End of TRY block, comes after CATCH
WHILE (exp) Start of WHILE loop

I/O Commands and Functions

CLOSE #channel Closes I/O channel
DELETE(fileName) Deletes fileName
GET #channel, vari [,var…] Reads data from I/O channel into variable
OPEN #channel, fileName, mode Opens named file on channel using access mode (“R”, “W” or “A”)
PRINTLINE #channel, expr Prints line to I/O channel
PUT #channel, expr Sends result of expression to I/O channel
READLINE #channel, stringvar [, stringvar…] Read line from I/O channel into string variable

Mathematical Functions

ABS(X) Absolute value of X
ACOS(X) Arc-cosine of X (Radians)
ACOSD(X) Arc-cosine of X (Degrees)
ACOSH(X) Hyperbolic Arc-cosine of X
ACOT(X) Arc-cotangent of X (Radians)
ACOTD(X) Arc-cotangent of X (Degrees)
ACOTH(X) Hyperbolic Arc-cotangent of X
ACSC(X) Arc-cosecant of X (Radians)
ACSCD(X) Arc-cosecant of X (Degrees)
ACSCH(X) Hyperbolic Arc-cosecant of X
ASEC(X) Arc-secant of X (Radians)
ASECD(X) Arc-secant of X (Degrees)
ASECH(X) Hyperbolic Arc-secant of X
ASIN(X) Arc-sine of X (Radians)
ASIND(X) Arc-sine of X (Degrees)
ASINH(X) Hyperbolic Arc-sine of X
ATAN(X) Arc-tangent of X (Radians)
ATAND(X) Arc-tangent of X (Degrees)
ATANH(X) Hyperbolic Arc-tangent of X
ATAN2(X,Y) Arc-tangent of X,Y (Radians)
ATAN2D(X,Y) Arc-tangent of X,Y (Degrees)
COS(X) Cosine of X (Radians)
COSD(X) Cosine of X (Degrees)
COSH(X) Hyperbolic Cosine of X
COT(X) Cotangent of X (Radians)
COTD(X) Cotangent of X (Degrees)
COTH(X) Hyperbolic Cotangent of X
CSC(X) Cosecant of X (Radians)
CSCD(X) Cosecant of X (Degrees)
CSCH(X) Hyperbolic Cosecant of X
DEG2RAD(X) Converts X from degrees to radians
EXP(X) Natural exponential of X (e^x)
EXP10(X) Base 10 exponential of X (10^x)
GRAD2RAD(X) Converts X from gradians to radians
LOG(X) Natural logarithm of X
LOG10(X) Base 10 logarithm of X
POW(X,Y) Raises X to power of Y
RAD2DEG(X) Converts X from radians to degrees
RAD2GRAD(X) Converts X from radians to gradians
RND(X) Returns random number
ROUND(X,Y) Rounds X to Y decimal places
SEC(X) Secant of X (Radians)
SECD(X) Secant of X (Degrees)
SECH(X) Hyperbolic Secant of X
SIN(X) Sine of X (Radians)
SIND(X) Sine of X (Degrees)
SINH(X) Hyperbolic Sine of X
SQRT(X) Square root of X
TAN(X) Tangent of X (Radians)
TAND(X) Tangent of X (Degrees)
TANH(X) Hyperbolic Tangent of X

String Functions

ASC(X) ASCII value of X
CHR$(X) Character value of X
LEFT$(X,Y) Leftmost Y characters of X
LEN(X) Number of characters in X
LOWER$(X) Converts X to lowercase
MID$(X,Y,Z) Extracts Z characters from X starting at Y
RIGHT$(X) Rightmost Y characters of X
STR$(X) Converts X to string.
TRIM$(X) Remove leading and trailing spaces from X
UPPER$(X) Converts X to uppercase
VAL(X) Returns value of X

Time and Date Functions

DATE(Y,M,D) Returns double representing date
DATETIME(Y,M,D,HH,MM,SS) Returns double representing date and time
DAY(X) Returns day associated with X
HOUR(X) Returns hour associated with X
MILLISECOND(X) Returns millisecond associated with X
MINUTE(X) Returns minute associated with X
MONTH(X) Returns month associated with X
NOW() Returns double value representing current date and time
SECOND(X) Returns second associated with X
TIME(HH,MM,DD) Returns double representing time
TODAY() Returns double representing current todays date
YEAR(X) Returns year associated with X

Type Checking Functions

isBoolean(X) Returns true if X is boolean otherwise false
isByte(X) Returns true if X is byte otherwise false
isComplex(X) Returns true if X is complex otherwise false
isDouble(X) Returns true if X is double otherwise false
isFloat(X) Returns true if X is float otherwise false
isInteger(X) Returns true if X is integer otherwise false
isLong(X) Returns true if X is long otherwise false
isShort(X) Returns true if X is short otherwise false
isString(X) Returns true if X is string otherwise false
isUnknown(X) Returns true if X is variant otherwise false

Type Conversion Functions

BOOLEAN(X) Convert X to boolean
BYTE(X) Convert X to byte
COMPLEX(X,Y) Convert (X, Yi) to complex
DOUBLE(X) Convert X to double
FLOAT(X) Convert X to float
IMAGINARY(X) Imaginary value of X as double
INTEGER(X) Convert X to integer
LONG(X) Convert X to long
REAL(X) Real value of X as double
SHORT(X) Convert X to short
STRING(X) Convert X to string
VARIANT(X) Convert X to variant

CNC Commands and Functions

METRIC Switch to metric units
IMPERIAL Switch to imperial units
START_SPINDLE Start spindle
STOP_SPINDLE Stop spindle
SET_FEED_RATE n Set feed rate
SET_SPINDLE_SPEED n Set spindle speed
SET_SAFE_DEPTH n Set depth above workpiece
SET_CUT_DEPTH n Set depth to use during cutting
GSAVE Save context (scale, rotations and translation) to stack
GRESTORE Restore context (scale, rotation and translation) from stack
SCALE sx,sy Scale by sx & sy
ROTATE angle Rotate subsequent drawing operations by angle (in degrees)
TRANSLATE tx,ty Moves zero coordinates by offset (tx,ty)
MOVE_TO x,y Move to x,y at fastest feed rate
DRAW_TO x,y Draw to x,y using set feed rate.

Tags: cnc basic