How to run a macro where "runonce" would run.
-
@mikeabuilder I assumed it was something you wanted to run once when the machine was first commissioned and then never again.
I wouldn't be running commands when the first boots up like that. All it would take would be a power cut and then for the printer to turn back on and boom, you may break something if you've been half way through a print. -
@mikeabuilder said in How to run a macro where "runonce" would run.:
Our problem is where to put it. We started by thinking it would be called from the last line in config.g, but this means it runs before the network is configured and so does not work for duet web control.
So if the macro youre wanting to run is supposed to happen when the printer is turned on, I'm wondering why it matters that duet web control doesn't work for the prompt. Won't the user be standing at the printer when it's turned on, so having just the paneldue prompt would be sufficient?
-
@mikeabuilder I agree with @jay_s_uk . This method may save a user a few seconds, however it fails in nasty ways. An alternative would be to have a prompt using M291 to ask the user if the printer should run the "autoheat" or whatever routine on startup.
-
Excellent points, particularly the bit about restarting after a power failure.
I think we'll follow Tony's final suggestion and ask the user for a positive affirmation to execute those startup steps.
I do wonder now about what happens with a Prusa after a mid-print power failure.
-
@mikeabuilder said in How to run a macro where "runonce" would run.:
I do wonder now about what happens with a Prusa after a mid-print power failure.
They have a power fail resume do they not?
Perhaps you could set a variable when a print is in progress and then check that on power up and prompt to resume?
-
Not sure if anyone is still interested in this topic, but I thought I'd give an update. I haven't implemented a complete solution yet, but I've gone down a few paths that ended in defeat. Here's my next pat (which I think will work completely (fingers crossed).
My goal is to run a prep_printer macro automatically, and only one time after the printer power up and network connection complete.
In config.g - "Copy" my prep_printer macro to "runonce.g". I'll do this by creating an input parameter "C" for my macro to trigger the copy. At the top of my macro, I'll have something like this:
IF exists(param.C) M28 "0:/sys/runonce.g" <the rest of my macro goes here> IF exists(param.C) M29
This should copy the body of my macro into runonce.g and close the new file. If someone sees a problem with this, please respond.
-
Since this is runonce, it will only run after config.g completes and also after network setup is complete.
-
I am a little scared that a Duet3D use of run_once.g might get disturbed, but the documentation on the Macros page does not give a warning that users should beware of this, so I'm taking the chance.
Now I need to worry about what happens after a power failure and I don't want this macro to run, Initially, I'll have a blocking (S=3) M291 message forcing the user to proceed or cancel. In the future I may implement something that looks at whether its a restart after a power failure, and then take appropriate action.
Now that I've written it out, this all seems too easy...
-
-
@mikeabuilder we have another user who has put a blocking M291 call near the end of config.g. It just happens that because this is a blocking message, RRF thinks that config.g has completed and it then enables the network; so the message does show up in DWC.
There is an associated bug: changes to default values set by M83 etc. in config.g no longer get copied to all GCode input channels when config.g completes. This will be fixed in RRF 3.5beta3 and in 3.4.6.
-
@dc42 - Thanks for the advice and tips. For now, I think we're safe using the runonce strategy. And we'll update to new fw as soon as it's available.
-
Well, this latest idea failed - Turns out that the M28 does not copy leading spaces at the beginning of lines, which breaks all meta command code blocks. I'm going to add another post to report that.
-
@mikeabuilder what are you using M28 to do?
-
Turns out that the M28 does not copy leading spaces at the beginning of lines, which breaks all meta command code blocks.
I agreee with what @jay_s_uk and @T3P3Tony have to say about your approach - it is potentially dangerous.
However, if you still want to follow the runonce idea, you might have another option than to copy a macro to file runonce.g with M28: create that file from text.
Using
echo > <filename> <expression>
to create a file and
echo >> <filename> <expression>
to append further lines should work as expected. For details, see GCode meta commands. -
@dc42 - I have a macro that walks the user through the steps we encourage from power-on to ready-to-print. This includes heating the bed, homing all axes, leveling the bed, and creating a fresh compensation mesh. We decided this should run one time at power-up in addition to being callable by the user at any time after power on.
The very first step when the macro runs is to require the user to clear a blocking M291 command to either proceed or cancel. The prevents the printer from executing this macro after a mid-print power failure (with crushing results).
The normal user interface is PanelDue, and we also want it to work well with DWC, so we relay on runonce.g to get the macro running after the network is set up.
I did have to omit the if exists(param.C) from the end of the macro because this was getting copied into runonce.g Executing the m29 at the end of the macro if param.C was not included doesn't seem to cause any issues, even though there was not a previous M28.
@infiniteloop - This is certainly another way to get the job done and I did create a short python script to create the file from my master macro. But RRF3.5 beta 3 has a fix for the leading spaces. I'll be testing it out tomorrow.
-
@mikeabuilder I've not heard of anyone using M28 for a long time. The standard way of creating a short file containing executable commands is to use the echo command with output redirection. For example:
echo >prepare.g "G28" echo >>prepare.g "G32"
The lines that you write don't have to be constants, you can build them up using string expressions if you want.
-
Thanks for all the assistance on this one. I'be installed 3.5beta3 and confirmed that M28 is including leading spaces on lines, and that my macro is working. I also have my python script to convert an existing script into one created by echo. So I'm wearing the belt and have the suspenders ready in case the belt breaks.
Thanks for all the wise counsel from the team here.