G-Code Macro $ System Functions
System Functions ¶
-
$is used for system provided functions - These are not case sensitive
- It is not recommended to put G-Codes or M-Codes on the same line as $ system functions
- Macro logic (if, while, variable assignment, etc.) can be combined with $ functions
| Command | Description |
|---|---|
| $PushModal | Save modal state to a stack |
| $PopModal | Load the last saved modal stack off the stack |
| $Msg | Blocks execution with OK dialog |
| $MsgBOOL | Blocks execution with yes/no confirmation dialog |
| $MsgLREAL | Blocks execution asking for a decimal value |
| $MsgDINT | Blocks execution asking for an integer value |
| $Terminate | Clears all buffers, motion is stopped, and all processing is stopped |
| $InSimulation | Returns 1 if in a simulation run, else 0 |
| $NULL | Null constant, equivalent to #0 |
| $PI | System’s best representation of , approximately 3.141592653589793 |
| $E | System’s best representation of , approximately 2.718281828459045 |
| $Alarm | Issues an Alarm. See example below. |
| $Warning | Issues a Warning. See example below. |
| $Info | Issues an Info message. See example below. |
$PushModal & $PopModal
- Saves the active G group state info to a stack.
- Intended for use with MTB/OEM macros to return to the main program with unchanged state
$MsgBOOL
- Yes/No style message box for confirmation
- Returns a value of 0 if the user pressed No or Cancel
- Returns a value of 1 if user pressed Yes
Example:
|
// yes/no message box for the user
IF[ $MsgBool["Proceed with cutting operation?"] == 0 ] G28 XYZ // go home M30 // end the program here END // User selected "ok" rest of the program... G01 X 100 Y 100 G01 X 150 ... |
$MsgLREAL
- Gets an LREAL value from the user
- Returns value provided by the user
- If canceled, the returned value will be NULL or \
Example:
|
// get a decimal number from the user
# 100 = $MsgLREAL["Enter feed rate value"] IF[ #100 == #0] // user must have canceled the dialog G28 XYZ // go home M30 // end the program here END IF[ #100 <= 0] $Msg["Feed rate too low! Ending program."] G28 XYZ // go home M30 // end the program here END IF[ #100 > 1000] // limit the feed rate value to 1000
#
100
= 1000
END // Now proceed with the program at the given feedrate G01 X 100 Y 100 F#100 G01 X 150 ... |
$Alarm, $Warning, and $Info
-
Set a string variable readable by the UI to the quoted string that follows the $Alarm, $Warning, or $Info command.
- Prepend alarm level text “Alarm: “, “Warning: “, or “Info: ” to the string
- Additionally, the string with the alarm level text and a time stamp should be prepended to a log file.
-
Set an alarm level integer value according to the type of active message. This may be used to color code the display on the UI according to the type.
- 0 - No active message. The string is set to “” and the integer is set to 0 upon reset of the
- 1 - Alarm
- 2 - Warning
- 3 - Info
Example:
|
#
100
= 0
//Check for divide by zero error IF[ #100 == 0] $Alarm["#100 cannot be zero"] END # 101 = 50 / #100 ... |
The UI would display the string variable with the string “Alarm: #100 cannot be zero” and the alarm level integer would be set to 1, allowing conditional coloring, for example setting the background to red. The $Alarm function issues a $Terminate-like command, immediately halting execution. If a warning or info type message were used, execution would proceed uninterrupted. The log file would be prepended with the string and time stamp.
Example Log File:
|
5-15-2025 14:13.01 Alarm: #100 cannot be zero
5-15-2025 14:10:17 Warning: something might happen 5-13-2025 09:33:59 Info: just so you know... ... |
#0
Used for checking if a variable is set or not.