Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Can't edit/save daemon.g that contains a 1 sec loop.

    Scheduled Pinned Locked Moved
    General Discussion
    9
    24
    776
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • zaptaundefined
      zapta @jay_s_uk
      last edited by

      Thanks @jay_s_uk.

      How does this work, if I do edit/save/test development cycles, do I need to set and reset the flag manually on each cycle, or is it a simpler way?

      fcwiltundefined 1 Reply Last reply Reply Quote 0
      • fcwiltundefined
        fcwilt @zapta
        last edited by

        @zapta

        You can create a couple of gcode files in the "macro" folder, with suitable names, for setting and clearing that global variable.

        Set the global variable to false and then you should be able to edit daemon.g with any problems.

        When done and the updated daemon.g file is saved, set the variable back to true to enable the loop once again.

        Frederick

        Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

        1 Reply Last reply Reply Quote 0
        • OwenDundefined
          OwenD @zapta
          last edited by OwenD

          @zapta
          When you say you are using a 1 second pause, I assume you're also running the macro using

          while 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.

          1 Reply Last reply Reply Quote 0
          • chrishammundefined
            chrishamm administrators @zapta
            last edited by

            @zapta I'll automate moving daemon.g to daemon.g.bak first before replacing it when it is edited.

            Duet software engineer

            zaptaundefined 1 Reply Last reply Reply Quote 2
            • zaptaundefined
              zapta @chrishamm
              last edited by zapta

              @chrishamm, do you mean that I can automate or that you will add automation?

              chrishammundefined 1 Reply Last reply Reply Quote 0
              • chrishammundefined
                chrishamm administrators @zapta
                last edited by

                @zapta I've already added that to the upcoming DWC v3.5-rc.2.

                Duet software engineer

                zaptaundefined 2 Replies Last reply Reply Quote 1
                • zaptaundefined
                  zapta @chrishamm
                  last edited by

                  Thanks @chrishamm !

                  1 Reply Last reply Reply Quote 0
                  • zaptaundefined
                    zapta @chrishamm
                    last edited by

                    @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.

                    chrishammundefined 1 Reply Last reply Reply Quote 0
                    • chrishammundefined
                      chrishamm administrators @zapta
                      last edited by

                      @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.

                      Duet software engineer

                      zaptaundefined DonStaufferundefined 2 Replies Last reply Reply Quote 0
                      • zaptaundefined
                        zapta @chrishamm
                        last edited by

                        @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?

                        1 Reply Last reply Reply Quote 0
                        • Tinchusundefined
                          Tinchus
                          last edited by

                          sorry to interrupt: my daemon.g now it is like this:

                          if global.runDaemon = true
                          while true
                          mycode
                          G4 S2

                          This 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?

                          zaptaundefined 1 Reply Last reply Reply Quote 0
                          • zaptaundefined
                            zapta @Tinchus
                            last edited by

                            @Tinchus, I believe that you need to have a conditional exit with the loop such that the code keeps evaluating the condition.

                            Tinchusundefined 1 Reply Last reply Reply Quote 0
                            • Tinchusundefined
                              Tinchus @zapta
                              last edited by Tinchus

                              @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

                              zaptaundefined dc42undefined 2 Replies Last reply Reply Quote 0
                              • zaptaundefined
                                zapta @Tinchus
                                last edited by

                                @Tinchus, to post code here you can use the </> button. It will preserve the indentation.

                                example:

                                code1
                                  code2
                                    code3
                                
                                zaptaundefined 1 Reply Last reply Reply Quote 0
                                • zaptaundefined
                                  zapta @zapta
                                  last edited by zapta

                                  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?

                                  Tinchusundefined 1 Reply Last reply Reply Quote 0
                                  • Tinchusundefined
                                    Tinchus @zapta
                                    last edited by

                                    @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...

                                    fcwiltundefined 1 Reply Last reply Reply Quote 0
                                    • fcwiltundefined
                                      fcwilt @Tinchus
                                      last edited by

                                      @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

                                      Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

                                      1 Reply Last reply Reply Quote 0
                                      • DonStaufferundefined
                                        DonStauffer @chrishamm
                                        last edited by

                                        @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?

                                        gloomyandyundefined 1 Reply Last reply Reply Quote 0
                                        • gloomyandyundefined
                                          gloomyandy @DonStauffer
                                          last edited by

                                          @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.

                                          DonStaufferundefined 1 Reply Last reply Reply Quote 0
                                          • dc42undefined
                                            dc42 administrators @Tinchus
                                            last edited by

                                            @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
                                            

                                            Duet WiFi hardware designer and firmware engineer
                                            Please do not ask me for Duet support via PM or email, use the forum
                                            http://www.escher3d.com, https://miscsolutions.wordpress.com

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Unless otherwise noted, all forum content is licensed under CC-BY-SA