Macro return oddities
-
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 tofalse
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 andthis.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.
-
@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 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?
-
@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 -
@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 byawait 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.
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. -
@NineMile Conditionals are not supported outside files. You should wrap it in a macro file and then invoke it using parameters.