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

How can I print 2 files consecutively?

Scheduled Pinned Locked Moved
General Discussion
3
12
522
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.
  • undefined
    usinjin
    last edited by 9 Oct 2023, 21:44

    I'm trying to figure out a good way to print 2 gcode files right after each other without rehoming/other intervention. I'm running into issues where I'm asking the Duet to select the new file for printing too soon, or the Duet is busy waiting for itself to not be busy. I tried this:

    G28
    M32 "0:/gcodes/file1.gc"
    while state.status = "processing"
    G4 P10
    M32 "0:/gcodes/file2.gc"

    Which ended up being rather hit or miss (it worked fine a couple of times). Leaving nothing in the while loop didn't work, but I don't think the dwell is the right answer either. Is there a better way to do this?

    undefined 1 Reply Last reply 10 Oct 2023, 00:57 Reply Quote 0
    • undefined
      jens55 @usinjin
      last edited by jens55 10 Oct 2023, 00:58 10 Oct 2023, 00:57

      @usinjin, I am probably not understanding what you are trying to do but PrusaSlicer and probably most other slicers offer to print things consecutively or at the same time. In most instances you would choose to print the two (or more) items at the same time but if the parts are not very tall then you might have clearance to print consecutively. I am only familiar with corexy and cartesian printers and other systems (Delta ... ) might have less of an issue with clearances.

      undefined 1 Reply Last reply 10 Oct 2023, 02:29 Reply Quote 1
      • undefined
        usinjin @jens55
        last edited by 10 Oct 2023, 02:29

        @jens55 In this case, it's for a pen plotter--2D only. The first gcode file is generated at runtime from text inputted by the user into a textbox and plotted at the top of the substrate. The second gcode file is plotted directly below it. The Duet is running in standalone mode with some Python helper functions running in the background.

        This macro seems to work fine, though I'm sure there's a better way of doing things--if anyone needs a more through explanation I am happy to provide one..I realize this is not trivial implementation of the system.

        G28 # home
        M32 "0:/gcodes/plot1.gc"
        while state.status = "processing"
        M102 # used as a NOP
        G4 P500 # Allow the state to switch
        M32 "0:/gcodes/plot2.gc"
        undefined 1 Reply Last reply 10 Oct 2023, 09:44 Reply Quote 0
        • undefined
          nikscha @usinjin
          last edited by 10 Oct 2023, 09:44

          @usinjin
          Maybe use a global variable that is set at the end of the first gcode?

          while global.is_not_finished
          M400

          But to be honest I don't see anything wrong with you solution ^^

          You could also use daemon.g to check whether your first file is done printing (by checking `state.status == "idle") and then start the new "print". This might become a bit bloated though.

          Stay in school

          undefined 1 Reply Last reply 10 Oct 2023, 09:52 Reply Quote 0
          • undefined
            usinjin @nikscha
            last edited by 10 Oct 2023, 09:52

            @nikscha A global is a good idea, I may try that. I thought the code I posted worked, but it broke the ability to stop or pause the print (both prints), and the console says nothing.

            undefined 1 Reply Last reply 10 Oct 2023, 10:02 Reply Quote 0
            • undefined
              nikscha @usinjin
              last edited by nikscha 10 Oct 2023, 10:03 10 Oct 2023, 10:02

              @usinjin I see, that's annoying ^^
              you probably want something like this:

              ;daemon.g
              if global.first_file_finished
              set global.first_file_finished = false
              G4 P5000 ; wait 5 seconds
              M32 "0:/gcodes/plot2.gc"

              Your first gcode file should then end with
              set global.first_file_finished = true

              Keep in mind that daemon.g only runs about every 10 seconds, so the delay could end up anywhere between 5 and 15 seconds. Let me know if that's a problem cause I got a solution ^^

              Edit: and you will need to add global first_file_finished = false to your config.g

              Stay in school

              undefined 1 Reply Last reply 11 Oct 2023, 07:36 Reply Quote 0
              • undefined
                usinjin @nikscha
                last edited by 11 Oct 2023, 07:36

                @nikscha Yeah, I considered using daemon.g but you're right in that the variable time gap between the prints would be an issue--interested to hear your potential alternative!

                undefined 1 Reply Last reply 11 Oct 2023, 09:40 Reply Quote 0
                • undefined
                  nikscha @usinjin
                  last edited by 11 Oct 2023, 09:40

                  @usinjin
                  Do the following:

                  ;daemon.g
                  while true
                  G4 P1
                  "rest of the code"

                  This will run "rest of the code" about 3-6 times a second, depending on your code, NOT 1000 times a second as the G4 P1 might suggest. AFAIK the G4 P1 gives controll back to the main process. You can read more here https://docs.duet3d.com/User_manual/Reference/Gcode_meta_commands under the daemon.g section

                  Stay in school

                  undefined 1 Reply Last reply 12 Oct 2023, 19:53 Reply Quote 0
                  • undefined
                    usinjin @nikscha
                    last edited by 12 Oct 2023, 19:53

                    @nikscha This seems to work okay, except there's a 10 second delay between the prints.

                    undefined 1 Reply Last reply 13 Oct 2023, 10:22 Reply Quote 0
                    • undefined
                      usinjin
                      last edited by usinjin 10 Dec 2023, 21:18 12 Oct 2023, 21:14

                      Oh, because the while loop isn't keeping daemon.g open.

                      This worked better:

                      while state.status != "idle" & job.file.fileName = "0:/gcodes/file1.gc"
                      G4 P1 ; Now daemon.g will remain open until file1.gc is done
                      if global.metadata_finished == true
                      set global.file1_finished = false
                      G4 P100
                      echo "Starting print 2.."
                      M32 "0:/gcodes/design2.gc

                      Instead of M2 at the end of the first file I have set global.file1_done = true.

                      In the event that it takes less than 10 seconds to plot the first message after daemon.g was last opened, the while loop doesn't keep the file open and it takes a bit longer to start printing the second file, but I can live with that.

                      Pause and stop seem to be working again.

                      1 Reply Last reply Reply Quote 0
                      • undefined
                        nikscha @usinjin
                        last edited by 13 Oct 2023, 10:22

                        @usinjin Did you indent the code? It should be inside the while loop.

                        Stay in school

                        undefined 1 Reply Last reply 18 Oct 2023, 01:12 Reply Quote 0
                        • undefined
                          usinjin @nikscha
                          last edited by 18 Oct 2023, 01:12

                          @nikscha I did--for some reason it didn't like that.

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