add_txt #
Print a message to the console.
Syntax #
add_txt(text) add_txt(text, is_warning)
Parameters #
- text – The message to print (required).
- is_warning – true shows a warning, false a normal message (optional, default false).
In warning mode, the <Settings> button at the bottom flashes red to alert the user that a new message has arrived.
Example #
-- Normal message
add_txt("Program started")
-- Warning message
add_txt("Temperature too high!", true)
send_gcode #
Push a G-code line into the command queue (does not wait for execution).
Syntax #
send_gcode(gcode)
Parameters #
- gcode – The G-code string to send (required).
Example #
-- Send a move command
send_gcode("G0 X10 Y20")
-- Send multiple commands (no wait)
send_gcode("G0 X0 Y0")
send_gcode("G1 Z-5 F100")
-- The script continues immediately, without waiting for the G-code to finish
Note: This function returns immediately after queuing the command and does not wait for the G-code to finish.
send_gcode_wait #
Send a G-code line and block until execution finishes.
Syntax #
send_gcode_wait(gcode)
Parameters #
- gcode – The G-code string to send (required).
Example #
-- Send a move and wait for completion
send_gcode_wait("G0 X10 Y20")
add_txt("Move done") -- Runs only after the G-code has finished
-- Run multiple commands sequentially
send_gcode_wait("G0 X0 Y0") -- waits
send_gcode_wait("G1 Z-5 F100") -- waits
add_txt("All commands finished")
Note: This function returns only when the command queue is empty and the machine state is IDLE.
get_language #
Get the current UI language.
Syntax #
get_language()
Parameters #
None.
Return value #
- “zh” – Chinese
- “en” – English
Example #
-- Get the current language
local lang = get_language()
-- Show different messages depending on the language
if lang == "zh" then
add_txt("这是中文提示")
elseif lang == "en" then
add_txt("This is an English message")
end
message_box #
Display a modal message dialog.
Syntax #
message_box(message) message_box(message, ok_text) result = message_box(message, ok_text, cancel_text)
Parameters #
- message – The main text shown in the dialog (required).
- ok_text – Label for the OK button (optional, default “OK”).
- cancel_text – Label for the Cancel button (optional; if omitted, only the OK button is shown).
Return value #
- 1 – User clicked OK.
- 0 – User clicked Cancel.
Example #
-- Simple notice
message_box("Tool change complete!")
-- Confirm dialog
local result = message_box("Continue execution?", "Yes", "No")
if result == 1 then
add_txt("User chose to continue")
else
add_txt("User cancelled")
end
sys_shutdown #
Shut down or reboot the system.
Syntax #
sys_shutdown(is_reboot) sys_shutdown(is_reboot, countdown_seconds)
Parameters #
- is_reboot – true to reboot, false to shut down (required).
- countdown_seconds – Confirmation countdown, range 3-30 seconds (optional, default 10).
Example #
-- Shut down (10-second countdown) sys_shutdown(false) -- Reboot (10-second countdown) sys_shutdown(true) -- Shut down (5-second countdown) sys_shutdown(false, 5) -- Reboot (15-second countdown) sys_shutdown(true, 15)
Note: A countdown outside the 3-30 second range is automatically clamped to the boundary. The user can press Cancel before the countdown ends to abort.
get_pos #
Get the current work coordinate of an axis (affected by G54/G92 and other coordinate-system offsets).
Syntax #
get_pos(axis)
Parameters #
- axis – X_AXIS / Y_AXIS / Z_AXIS / A_AXIS / B_AXIS (required).
Return value #
- Current work-coordinate value of the axis (number).
Example #
-- Read work coordinates of all 5 axes
local wx = get_pos(X_AXIS)
local wy = get_pos(Y_AXIS)
local wz = get_pos(Z_AXIS)
local wa = get_pos(A_AXIS)
local wb = get_pos(B_AXIS)
add_txt(string.format("Work X=%.3f Y=%.3f Z=%.3f A=%.3f B=%.3f",
wx, wy, wz, wa, wb))
get_machine_pos #
Get the current machine coordinate of an axis (not affected by work-coordinate-system offsets).
Syntax #
get_machine_pos(axis)
Parameters and return value are the same as get_pos.
Example #
local mx = get_machine_pos(X_AXIS)
local my = get_machine_pos(Y_AXIS)
local mz = get_machine_pos(Z_AXIS)
add_txt(string.format("Machine X=%.3f Y=%.3f Z=%.3f", mx, my, mz))
Axis index constants #
- X_AXIS = 0
- Y_AXIS = 1
- Z_AXIS = 2
- A_AXIS = 3
- B_AXIS = 4
Note: Coordinate values are reported by the controller status line in real time (~5 Hz). Right after a motion command such as G38.2, the values are not yet updated and may still reflect the position before the move. Always call
send_gcode_wait first so the queue empties and the state returns to IDLE before reading.