Solved M291 S4 with timeout only runs a couple of commands
-
I'm trying to make a Macro that will shut down the printer after giving the user a 60 second window to cancel it once a print is finished. I created this macro called PowerOff.g that looks like this:
M98 P"0:/macros/YesNoInput.g" H"Shutdown Requested" S"Start the shutdown procedure?" T60 if (input == 0) echo "Shutting down procedure started" echo "test" M18 ; Turn off motors M568 H1 R41 S0 ; Set hotend standby to 41 and active to 0 M568 H1 A1 ; Set hotend to standby temp M140 S0 ; Turn bed off M116 H1 ; Wait for hotend to reach 41 degrees (This is the lowest you can wait for a temp) M568 H1 A2 ; Turn hotend back to active M42 P0 S1 ; Turn bed ps off M42 P1 S1 ; Turn main ps off echo "Sutdown finished" else echo "Shutdown won't run" echo "Script finished"
This macro calls another macro I call "YesNoInput.g." The idea behind this is to display a yes button and a cancel button. The popup will automatically timeout and select cancel, making the printer proceed to shut down. Here is "YesNoInput.g":
M291 R{param.H} P{param.S} K{"Yes",} T{param.T} S4 F"Yes" J1
I put this in an external macro, so it doesn't cancel my main macro that does the shutdown procedure.
The problem is when the popup is shown and the user presses cancel or when the popup times out, I only see "Shutting down procedure started" in my consol. However, I don't see "test" in my consol, and the shutdown sequence doesn't start.
I saw this solution but I wanted to use the functionality built into the M291 command. Any help would be greatly appreciated!
M122 Output
=== Diagnostics ===
RepRapFirmware for Duet 3 Mini 5+ version 3.5.0-rc.3 (2024-01-24 17:56:48) running on Duet 3 Mini5plus Ethernet (SBC mode)
Board ID: 9Z2U8-1B67A-G65J0-401GL-K592Z-ZUDS9
Used output buffers: 1 of 40 (18 max)
=== Duet Control Server ===
Duet Control Server version 3.5.0-rc.3 (2024-01-26 12:34:19)
Code buffer space: 4096
Configured SPI speed: 8000000Hz, TfrRdy pin glitches: 0
Full transfers per second: 39.48, max time between full transfers: 73.9ms, max pin wait times: 59.6ms/9.7ms
Codes per second: 3.55
Maximum length of RX/TX data transfers: 4558/2432 -
-
@kerfun I got a solution that does what I wanted to do. I have my power off script now that looks like this:
var now = state.time var timeOut = 60 M98 P"0:/macros/YesNoInput.g" H"Shutdown Requested" S"Start the shutdown procedure?" T{var.timeOut} var startShutdown = true if state.time - var.now >= {var.timeOut} set var.startShutdown = true elif input == null set var.startShutdown = false if var.startShutdown == true echo "shutdown started" M18 ; Turn off motors M568 H1 R41 S0 ; Set hotend standby to 41 and active to 0 M568 H1 A1 ; Set hotend to standby temp M140 S0 ; Set bed to 0 M116 H1 ; Wait for hotend to reach 41 degrees (This is the lowest you can wait for a temp) M568 H1 A2 ; Set hotend back to active M42 P0 S1 ; Turn bed ps off M42 P1 S1 ; Turn main ps off
And then I have my YesNoInput.g file that looks like this:
M291 R{param.H} P{param.S} K{"Yes",} S4 F"Yes" T{param.T} J1
When the print is done I have the slicer always call the shutdown macro. When the shutdown macro runs it will ask the user if they want the printer to power down (in case they want to keep printing). If the user presses "Yes" the printer will start the shutoff procedure (the shutdown procedure usually takes pretty long because I want to wait for the hotend to cool off). If the user doesn't press any buttons on the message the printer will shut off. If the user presses "cancel" before the 60 seconds, the printer will stay on.
-
@kerfun I think you’re hitting the same problem as reported in this thread https://forum.duet3d.com/topic/34945/meta-gcode-result-variable-inconsistent-with-docs where hitting cancel immediately cancels the current job or macro. See @T3P3Tony response later in the thread for a workaround.
Ian
-
@droftarts the solution in that post doesn't seem to work for me as I want the prompt to timeout after a minute and start the shutdown process. This requires me to put the J1 in the M291 command which is giving me inconstant results. It seems like the proposed functionality of a J2 option would work for me though, but this isn't implemented yet.
I also thought that canceling a child Macro wouldn't cancel the parent macro from this post.
I tried making a new test that would call the same macro I posted above, "YesNoInput.g." With this new test way I could see if the parent macro is being cancelled by the child macro.
M98 P"0:/macros/YesNoInput.g" H"Bed was cold at startup" S"Wait 10 minuets for expansion?" T5 if (input == 0) echo "running yes" echo "still runnning yes" else echo "running no" echo "still running no" echo "done"
When this Macro is run, and I select Yes in the popup "running yes", "still running yes", and "done" are printed to the console. When I run this macro and I select cancel the first time I don't get anything printed to the console. That would make me think the child macro is canceling the parent macro. However, when I run the Macro again and select cancel the popup prints "running no" to the console and that's it. This would make it seem like the child macro is partially cancelling the parent macro.
-
@kerfun I got a solution that does what I wanted to do. I have my power off script now that looks like this:
var now = state.time var timeOut = 60 M98 P"0:/macros/YesNoInput.g" H"Shutdown Requested" S"Start the shutdown procedure?" T{var.timeOut} var startShutdown = true if state.time - var.now >= {var.timeOut} set var.startShutdown = true elif input == null set var.startShutdown = false if var.startShutdown == true echo "shutdown started" M18 ; Turn off motors M568 H1 R41 S0 ; Set hotend standby to 41 and active to 0 M568 H1 A1 ; Set hotend to standby temp M140 S0 ; Set bed to 0 M116 H1 ; Wait for hotend to reach 41 degrees (This is the lowest you can wait for a temp) M568 H1 A2 ; Set hotend back to active M42 P0 S1 ; Turn bed ps off M42 P1 S1 ; Turn main ps off
And then I have my YesNoInput.g file that looks like this:
M291 R{param.H} P{param.S} K{"Yes",} S4 F"Yes" T{param.T} J1
When the print is done I have the slicer always call the shutdown macro. When the shutdown macro runs it will ask the user if they want the printer to power down (in case they want to keep printing). If the user presses "Yes" the printer will start the shutoff procedure (the shutdown procedure usually takes pretty long because I want to wait for the hotend to cool off). If the user doesn't press any buttons on the message the printer will shut off. If the user presses "cancel" before the 60 seconds, the printer will stay on.
-
-