Can't edit/save daemon.g that contains a 1 sec loop.
-
@zapta
When you say you are using a 1 second pause, I assume you're also running the macro usingwhile true / your code G4 S1
You can
- rename the file e.g "daemon.old"
- do your edit
- rename back to daemon.g
If you go the global route you need to ensure that daemon.g includes code to exit the macro if the global is false
if global.runDaemon = false M99
Otherwise it won't actually exit the macro
Bear in mind that if it's still named daemon.g then RRF will open it again as part of the normal 10 second cycle.
So it's still possible to get a file open error if you try to save at that time. -
@zapta I'll automate moving daemon.g to daemon.g.bak first before replacing it when it is edited.
-
@chrishamm, do you mean that I can automate or that you will add automation?
-
@zapta I've already added that to the upcoming DWC v3.5-rc.2.
-
Thanks @chrishamm !
-
@chrishamm, when you daemon and save the new version. Do you also stop somehow the old version that runs with the infinite loop?
When I simulate it here with manual rename, I also need to restart the Duet for the new daemon.g to take affect.
-
@zapta No, it will still run forever unless you exit the macro file somewhere or reset the board after your change. If you want to perform an action once per second in daemon.g, consider adding a while loop like
while iterations < 10 ; do something G4 S1 ; wait a second
to daemon.g instead.
-
@chrishamm, having a loop just for a single 10sec slot is a good idea. I will give it a try. My concern is the timing on boundary of daemon.g invocations. Having the reset the board is also reasonable since it's a big red accessible button on the screen.
Let's say that daemon.g is invoked at time T=0 and takes 10.5 secs to complete. When will the next invocation of daemon.g occur, at T=10.5 or at T=20?
-
sorry to interrupt: my daemon.g now it is like this:
if global.runDaemon = true
while true
mycode
G4 S2This should allow me to stop it if I set the variable to false, and if it is true, the daemon.g executes every 2 seconds, is this ok?
-
@Tinchus, I believe that you need to have a conditional exit with the loop such that the code keeps evaluating the condition.
-
@zapta sorry, I paste but indentation was deleted, the daemong looks like this:
if global.runDaemon = true while true mycode G4 S2
And of course inside the "mycode" section, Have some G4 S0.5 to be sure the while is not running forever.
This is workign ok for me now, but I have just noticed that if I delete the if global.runDaemon = true I still can edit and save the daeom.g file... may be with latest versions of firmware now the file is not locked for edition anymore while still being active?
PD: indentation was erased again... ok, beleiveme , my daemon is running ok every 2 seconds jajajaja
-
@Tinchus, to post code here you can use the </> button. It will preserve the indentation.
example:
code1 code2 code3
-
Once you check the flag once and enter the infinite loop, the flag is not examined anymore so the loop will not stop when runDaemon becomes false.
How do you sent the flag to false to stop the daemon and do you restart the machine to do so?
-
@zapta yes, I restarted the machine several times, for some reason I can edit and save the daemon.g without renaming it at all. I just edit it on the iterface, save it and it is being accepted...
-
@Tinchus said in Can't edit/save daemon.g that contains a 1 sec loop.:
@zapta yes, I restarted the machine several times, for some reason I can edit and save the daemon.g without renaming it at all. I just edit it on the iterface, save it and it is being accepted...
That has been my experience as well.
Frederick
-
@chrishamm What happens if, for example, you have the loop set for a much higher value, say, 100 iterations? I'm asking to understand how the daemon.g file works, so I can make good decisions on how to use it.
For example, let's say you set it to 100. The file gets run every 10 seconds, so what happens if it's still running 10 seconds after it was run, due to the loop? Will a second instance run, or does the 10 seconds not even start until the original run ends? The former would get messy memory wise; the latter would mean it wouldn't run every 10 seconds, but instead every 10 seconds plus how long it takes to run. Or, does it "know" it's already running and skip the trigger? That would make the period between runs unpredictable.
Also, what's the best way for it to check whether there's a print job running at the moment, so I can write code to only execute during a job?
-
@DonStauffer said in Can't edit/save daemon.g that contains a 1 sec loop.:
Also, what's the best way for it to check whether there's a print job running at the moment, so I can write code to only execute during a job?
Take a look at the object model documentaton: https://github.com/Duet3D/RepRapFirmware/wiki/Object-Model-Documentation in particular the state.status it probably has what you need.
-
@Tinchus said in Can't edit/save daemon.g that contains a 1 sec loop.:
if global.runDaemon = true while true mycode G4 S2
Use this instead:
while global.runDaemon mycode G4 S2
-
@gloomyandy That may work, but it does raise questions:
-
If state.status is "busy", does that imply a job is running, or is it impossible to tell whether maybe it's just executing a G1 from the console, for instance? Would you have to wait for it not to be busy to determine whether there's a job running?
-
Does running a macro count as "processing" or is that status only when an actual print job is running?
Put another way, what would the test be for simply whether a job is running/unfinished or not, regardless of what else exactly is happening at the time?
-
-
@DonStauffer state.status is "processing" only while a job is running from SD card. It's still "processing" even if the job calls a macro.