User Defined Commands and exit code
- Axolito
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 24
- Thank you received: 5
04 Jan 2025 10:52 #318039
by Axolito
User Defined Commands and exit code was created by Axolito
To configure my machine, I've already created several user defined commands. I've always followed the examples in the documentation, where there's always the line “exit 0” at the end.
Today I wanted to set up a custom M code that runs Zenity to display information to the user and wait for him to click on OK. I then wondered how LinuxCNC would behave if the exit code was not equal to zero.
I searched the documentation but found no mention of this apart from the “exit 0” in the examples. So I did a few tests: in Gmoccapy, a macro that uses a custom M code with “exit 1” seems to cancel the execution of the macro. This suits me because I could use Zenity to ask whether or not the probe is correctly positioned. Clicking on “no” cancels the probe macro.
It's a pity that exit codes are not documented.
Is my way of doing things correct?
Will the documentation of user defined commands be completed?
Today I wanted to set up a custom M code that runs Zenity to display information to the user and wait for him to click on OK. I then wondered how LinuxCNC would behave if the exit code was not equal to zero.
I searched the documentation but found no mention of this apart from the “exit 0” in the examples. So I did a few tests: in Gmoccapy, a macro that uses a custom M code with “exit 1” seems to cancel the execution of the macro. This suits me because I could use Zenity to ask whether or not the probe is correctly positioned. Clicking on “no” cancels the probe macro.
It's a pity that exit codes are not documented.
Is my way of doing things correct?
Will the documentation of user defined commands be completed?
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 3998
- Thank you received: 1726
04 Jan 2025 12:44 - 04 Jan 2025 14:38 #318057
by Aciera
Replied by Aciera on topic User Defined Commands and exit code
I just tested this and an exit value other than '0' seems to stop gcode program execution but does not issue any message to the operator, which seems a bit surprising.
I have created a Pull Request to add a note about behavior on exit codes other than 0.
Thanks for bringing this up.
I have created a Pull Request to add a note about behavior on exit codes other than 0.
Thanks for bringing this up.
Last edit: 04 Jan 2025 14:38 by Aciera. Reason: Update and link to PR
The following user(s) said Thank You: Axolito
Please Log in or Create an account to join the conversation.
- MaHa
- Offline
- Platinum Member
Less
More
- Posts: 405
- Thank you received: 163
04 Jan 2025 13:31 #318060
by MaHa
Replied by MaHa on topic User Defined Commands and exit code
Just some extracted lines, from my Mcode. Program gets aborted or continues, using tkinter askyesno.
#! /usr/bin/python3
import sys
import linuxcnc
c = linuxcnc.command()
if not tkinter.messagebox.askyesno(msg1,msg2):
c.abort()
exit(1)
exit(0)
The following user(s) said Thank You: Aciera
Please Log in or Create an account to join the conversation.
Moderators: HansU
Time to create page: 0.101 seconds