Meta Command Limit
-
I've been having a play around with meta commands and conditional g-code over the past couple of days to see if/how I can use it to make some tasks a bit more smart and/or automated. Below is an example of a simple script(?) I was experimenting with that when a tool is selected, should display the current tool number, setpoint, current temperature and the difference between the two. For what I was aiming for, I'm only actually interested in the difference value, however, I was building it up bit at a time to make sure I was reading the correct part of the object model.
However, I believe I've now reached a point where I've filled up a buffer and was wondering a) what the current length limit is (SPI buffer?), b) could it be increased, c) I guess this could possibly be avoided in the future when variables get implemented...?
I appreciate that my example below is extreme and it's unlikely that anyone would actually be upset if they couldn't this particular example. Therefore, this isn't actually a request to have the limit increased, it's currently more an observation that there is a limit, whether it's likely to be sufficient for other typical use cases, and whether there might be any smarter way of doing this sort of thing?
So, this works:
if {state.currentTool == -1} M291 P"No tool selected" S1 else M291 P{ "Tool:" ^ state.currentTool ^ " | Setpoint:" ^ heat.heaters[tools[state.currentTool].heaters[0]].active ^ " | Current:" ^ heat.heaters[tools[state.currentTool].heaters[0]].current } S1
This also works:
if {state.currentTool == -1} M291 P"No tool selected" S1 else M291 P{ "Difference:" ^ (heat.heaters[tools[state.currentTool].heaters[0]].active - heat.heaters[tools[state.currentTool].heaters[0]].current) } S1
This, however, throws an exception in DWC of
Failed to serialize code
.if {state.currentTool == -1} M291 P"No tool selected" S1 else M291 P{ "Tool:" ^ state.currentTool ^ " | Setpoint:" ^ heat.heaters[tools[state.currentTool].heaters[0]].active ^ " | Current:" ^ heat.heaters[tools[state.currentTool].heaters[0]].current ^ " | Difference:" ^ (heat.heaters[tools[state.currentTool].heaters[0]].active - heat.heaters[tools[state.currentTool].heaters[0]].current) } S1
Here's the log from DCS:
May 01 12:53:19 starttex DuetControlServer[1779]: [info] Starting macro file 0:/macros/Experimental/target temperatures on channel HTTP May 01 12:53:19 starttex DuetControlServer[1779]: [error] Code M291 P{ "Tool:" ^ state.currentTool ^ " | Setpoint:" ^ heat.heaters[tools[state.currentTool].heaters[0]].active ^ " | Current:" ^ heat.heaters[tools[state.currentTool].heaters[0]].current ^ " | Difference:" ^ (heat.heaters[tools[state.currentTool].heaters[0]].active - heat.heaters[tools[state.currentTool].heaters[0]].current) } S1 has thrown an exception May 01 12:53:19 starttex DuetControlServer[1779]: System.ArgumentException: Failed to serialize code May 01 12:53:19 starttex DuetControlServer[1779]: ---> System.ArgumentException: Destination is too short. (Parameter 'destination') May 01 12:53:19 starttex DuetControlServer[1779]: at DuetControlServer.SPI.Serialization.Writer.WriteCode(Span`1 to, Code code) in /home/christian/duet/DuetSoftwareFramework/src/DuetControlServer/SPI/Serialization/Writer.cs:line 231 May 01 12:53:19 starttex DuetControlServer[1779]: at DuetControlServer.SPI.DataTransfer.GetCodeSize(Code code) in /home/christian/duet/DuetSoftwareFramework/src/DuetControlServer/SPI/DataTransfer.cs:line 523 May 01 12:53:19 starttex DuetControlServer[1779]: --- End of inner exception stack trace --- May 01 12:53:19 starttex DuetControlServer[1779]: at DuetControlServer.SPI.DataTransfer.GetCodeSize(Code code) in /home/christian/duet/DuetSoftwareFramework/src/DuetControlServer/SPI/DataTransfer.cs:line 527 May 01 12:53:19 starttex DuetControlServer[1779]: at DuetControlServer.SPI.Channel.Processor.ProcessCode(Code code) in /home/christian/duet/DuetSoftwareFramework/src/DuetControlServer/SPI/Channel/Processor.cs:line 283 May 01 12:53:19 starttex DuetControlServer[1779]: at DuetControlServer.SPI.Interface.ProcessCode(Code code) in /home/christian/duet/DuetSoftwareFramework/src/DuetControlServer/SPI/Interface.cs:line 211 May 01 12:53:19 starttex DuetControlServer[1779]: at DuetControlServer.Commands.Code.Process() in /home/christian/duet/DuetSoftwareFramework/src/DuetControlServer/Commands/Code.cs:line 425 May 01 12:53:19 starttex DuetControlServer[1779]: at DuetControlServer.Commands.Code.ExecuteInternally() in /home/christian/duet/DuetSoftwareFramework/src/DuetControlServer/Commands/Code.cs:line 337 May 01 12:53:19 starttex DuetControlServer[1779]: [info] Aborted macro file 0:/macros/Experimental/target temperatures May 01 12:53:19 starttex DuetControlServer[1779]: [error] Failed to execute M291 in target temperatures: [ArgumentException] Failed to serialize code
(edit: I've just tried replacing the M291 commands with echos instead and that errors saying the argument is too long (>255)... so I guess that's the limit?)
-
The maximum length of a line of GCode supported by RRF on Duets, excluding leading indentation and trailing comments, is 160 characters. The maximum nesting depth of if- and while-commands is 10. DCS may have different limits.
-
PS - I can increase the maximum line length on Duet 3 because there is plenty of RAM available. Not so easy on Duet 2.
-
Thanks for that! As it happens, I'm actually using this on setups with D3 with SBC,and I guess in these cases the limit is in DCS?
However, I do have other systems running D2, so this is still really useful to know.