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

    Macro return oddities

    Scheduled Pinned Locked Moved
    Duet Web Control
    2
    6
    174
    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.
    • NineMileundefined
      NineMile
      last edited by

      Again, not necessarily a DWC issue but I'm noticing it while writing a plugin for DWC.

      I build up a command to run a custom macro, and then when the user clicks a button I submit the macro code to RRF using something like this:

      async runProbe() {
          this.probing = true;
          await store.dispatch("machine/sendCode", this.getProbeCode());
          this.probing = false;
      }
      

      this.getProbeCode() returns a string that looks like this: G6520.1 Q0 N0 H10 I10 P5 T10 C5 O2 J297.827 K110.56 L-4.965 which is all the values required to run a given probe macro.

      Now what I'm seeing is this.probing being set to false before the probing macro itself is finished. The probing macro runs other macros and then uses some of that information to print output.

      It seems like as soon as the top level probing macro calls the first 'child' macro (which is what actually loops and runs the probes), the call to G6520.1 returns and this.probing is set to false.

      My understanding is that we should be able to wait for G6520.1 to run completely before returning but oddly, this doesn't seem to be the case.

      Is this behaviour expected? I'm running RRF 3.6.0-beta.2 (stm32) with matching DWC.

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

        @NineMile I suppose you're running your board in standalone mode? If yes, see this related issue: https://github.com/Duet3D/RepRapFirmware/issues/925 DWC cannot yet determine when a code has actually finished, so it assumes the last code has finished once it receives a new reply. In SBC mode, you should only get back a reply of the requested code as soon as it finishes, but not before.

        chrishamm created this issue in Duet3D/RepRapFirmware

        open Return full code reply via HTTP rr_reply code for corresponding rr_gcode calls #925

        Duet software engineer

        NineMileundefined 2 Replies Last reply Reply Quote 0
        • NineMileundefined
          NineMile @chrishamm
          last edited by

          @chrishamm said in Macro return oddities:

          @NineMile I suppose you're running your board in standalone mode? If yes, see this related issue: https://github.com/Duet3D/RepRapFirmware/issues/925 DWC cannot yet determine when a code has actually finished, so it assumes the last code has finished once it receives a new reply. In SBC mode, you should only get back a reply of the requested code as soon as it finishes, but not before.

          Yep, running in standalone mode. I would've tried to run the same command via serial to see when it returned but I broke the USB port off my board last week so that's no longer an option 😭

          I'd guess because the macro being called is "composite", and the first sub macro prints output when it returns, that is deemed to be the called command completing.

          So if I were to remove the echoed output from the macros (it's actually less important if I can load probing data directly into DWC) then it should work?

          NineMileundefined 1 Reply Last reply Reply Quote 0
          • NineMileundefined
            NineMile @NineMile
            last edited by

            @NineMile said in Macro return oddities:

            So if I were to remove the echoed output from the macros (it's actually less important if I can load probing data directly into DWC) then it should work?

            Update: This does work, if the macros don't output any information via echo {} then the UI waits correctly for the command to run. Thanks @chrishamm 👍

            1 Reply Last reply Reply Quote 0
            • NineMileundefined
              NineMile @chrishamm
              last edited by

              @chrishamm sorry for all the questions but maybe you know the answer to this one too:

              I'm trying to do the following, which runs a Modbus discovery command on a set number of addresses. The idea is to loop within meta gcode, because if the M260.4 command is called directly by await this.sendCode() then the response variable is defined at top level and then exists for the lifetime of the HTTP gcode buffer.

              // Use a RRF meta gcode loop, so we can use the same response variable for M260.4
                              
                              await this.sendCode(`
                                  if { !exists(global.modbusResult) }
                                      global modbusResult = { null }
                              
                                  set global.modbusResult = { vector(${this.maxAddressesPerDiscovery}, null) }
                              
                                  while { iterations < ${this.maxAddressesPerDiscovery} }
                                      G4 P100
                                      M260.4 P${this.selectedPort} A{${this.addressStart} + iterations} B{0x08,0x00,0x00,0xBE,0xEF} R5 V"modbusResponse"
                                      set global.modbusResult[iterations] = { var.modbusResponse }
                              `);
                              
                              const modbusResult = store.state.machine.model.global.get("modbusResult");
                              
              

              If I trigger the above code, I get an error that looks like the lines aren't formatted properly.

              dwc_error.png

              What's the correct way to send code like this with conditionals from DWC? Is there one? I think I've seen other plugins create a macro file temporarily and then execute it using M98 but that seems like a rather roundabout way to execute macro code directly.

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

                @NineMile Conditionals are not supported outside files. You should wrap it in a macro file and then invoke it using parameters.

                Duet software engineer

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