test_code()

Tests a G-code program provided as a string for validity without executing it.

Syntax

planetcnc.test_code(gcode)

Parameters

Parameter Type Description
gcode str A string containing the G-code commands to be tested.

Return Value

Examples

#! /usr/bin/env python 
 
# Test a G-code program provided as a string.
gcode_program = "G00 X0 Y0\nG01 X100 Y100\nM03"
result = planetcnc.test_code(gcode_program)
if result == 0:
    print("G-code is valid.")
elif result > 0:
    print(f"G-code error detected at line {result}.")
else:
    print("G-code test failed or an unspecified error occurred.")

See also

open_file
open_code
start_file
start_code
test_file
test_code