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

    One addition for the Gcode dictionary - nested M291 command

    Scheduled Pinned Locked Moved
    Documentation
    2
    3
    252
    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.
    • NeoDueundefined
      NeoDue
      last edited by NeoDue

      If you use nested M291 commands with a messagebox mode S4... S7 (the ones that create an "input" variable), the last message box overwrites the initial one, which may result in the wrong initial task being executed:

      Here is a quick example. If you choose "load filament into left hotend" which is the first option in the initial message box (--> input = 0) and then choose the option not to wipe or clean the hotend nozzles, then the input variable changes to 2 which causes the option "load filament for both hotends" of the initial message box to be executed.

      M291 S4 K{"left","right","both","back"} P"Please choose the hotend to load" R"load filament"
          if input = 0
              ; do stuff... 
              M291 S4 K{"wipe","manual clean","done"} P"Wipe or clean the hotend nozzle?" R"load filament - left"
                  if input = 0
                      ; wipe and finish
                  if input = 1
                      ; move to a convenient cleaning position and request cleaning
                  if input = 2
                      break ; finish
          if input = 1
              ; do stuff... 
              M291 S4 K{"wipe","manual clean","done"} P"Wipe or clean the hotend nozzle?" R"load filament - right"
                          if input = 0
                              ; wipe and finish
                          if input = 1
                              ; move to a convenient cleaning position and request cleaning
                          if input = 2
                              break ; finish
          if input = 2
              ; do stuff... 
                      M291 S4 K{"wipe","manual clean","done"} P"Wipe or clean the hotend nozzles?" R"load filament - both"
                          if input = 0
                              ; wipe and finish
                          if input = 1
                              ; move to a convenient cleaning position and request cleaning
                          if input = 2
                              break ; finish
          if input = 3
              ; finish
      

      This behaviour is logical if you keep in mind that the message boxes fill the variable "input" which only exists once per macro, in opposite to the "iterations" loop counter.

      But since I did not think this through and kept searching for some typo for days until the penny dropped 😵 , I hereby vote to add a corresponding remark to the notes of M291 in the Gcode dictionary - something like this maybe: " NOTE: If you use more than one message box with mode S4... S7 within the the same macro, keep in mind that the same input variable is used for all message boxes, which means it only shows the input from the last message box."

      droftartsundefined 1 Reply Last reply Reply Quote 2
      • droftartsundefined
        droftarts administrators @NeoDue
        last edited by

        @NeoDue Thanks for noting this. Wouldn't using elif rather than if statements for the subsequent conditional statements get around this?

        Ian

        Bed-slinger - Mini5+ WiFi/1LC | RRP Fisher v1 - D2 WiFi | Polargraph - D2 WiFi | TronXY X5S - 6HC/Roto | CNC router - 6HC | Tractus3D T1250 - D2 Eth

        NeoDueundefined 1 Reply Last reply Reply Quote 0
        • NeoDueundefined
          NeoDue @droftarts
          last edited by

          @droftarts you are right, "elif" works as well - and is easier. Thanks!

          But I would add the note nevertheless, in case someone relies on the input variable for something else.

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