diff --git a/src/DuetControlServer/Codes/Processor.cs b/src/DuetControlServer/Codes/Processor.cs index 54794e51b..501aabb82 100644 --- a/src/DuetControlServer/Codes/Processor.cs +++ b/src/DuetControlServer/Codes/Processor.cs @@ -155,22 +155,43 @@ public static async ValueTask StartCodeAsync(Commands.Code code) // Deal with priority codes if (code.Flags.HasFlag(CodeFlags.IsPrioritized)) { - // Check if the code has to be moved to another channel first + // Process this priority code here if it is idle if (processor.IsIdle(code)) { await processor.WriteCodeAsync(code, stage); return; } - // Move priority codes to an empty code channel (if possible) + // Otherwise move it to another idle code channel with the same emulation type (if possible) + using (await Model.Provider.AccessReadOnlyAsync()) + { + Compatibility compatibility = Model.Provider.Get.Inputs[code.Channel]?.Compatibility ?? Compatibility.RepRapFirmware; + for (int input = 0; input < Inputs.Total; input++) + { + CodeChannel channel = (CodeChannel)input; + if (channel != code.Channel && channel is not CodeChannel.File and not CodeChannel.File2) + { + ChannelProcessor next = _processors[input]; + if (Model.Provider.Get.Inputs[channel]?.Compatibility == compatibility && next.IsIdle(code)) + { + code.Channel = channel; + await next.WriteCodeAsync(code, stage); // This can't block if the channel is idle + return; + } + } + } + } + + // Otherwise move it to an arbitrary idle code channel (if possible) for (int input = 0; input < Inputs.Total; input++) { - if ((CodeChannel)input != code.Channel) + CodeChannel channel = (CodeChannel)input; + if (channel != code.Channel && channel is not CodeChannel.File and not CodeChannel.File2) { ChannelProcessor next = _processors[input]; if (next.IsIdle(code)) { - code.Channel = (CodeChannel)input; + code.Channel = channel; await next.WriteCodeAsync(code, stage); return; } diff --git a/src/DuetControlServer/Commands/Generic/SimpleCode.cs b/src/DuetControlServer/Commands/Generic/SimpleCode.cs index 62e11af30..1fd23f9a1 100644 --- a/src/DuetControlServer/Commands/Generic/SimpleCode.cs +++ b/src/DuetControlServer/Commands/Generic/SimpleCode.cs @@ -91,9 +91,9 @@ public override async Task Execute() code.Flags |= CodeFlags.Asynchronous; } - // M108, M112, M122, and M999 (B0) always go to an idle channel so we (hopefully) get a low-latency response + // M108, M112, M122, M292, and M999 (B0) always go to an idle channel so we (hopefully) get a low-latency response if (code.Type == CodeType.MCode && - (code.MajorNumber == 108 || code.MajorNumber == 112 || code.MajorNumber == 122 || (code.MajorNumber == 999 && code.GetInt('B', 0) == 0))) + (code.MajorNumber is 108 or 112 or 122 or 292 || (code.MajorNumber == 999 && code.GetInt('B', 0) == 0))) { code.Flags |= CodeFlags.IsPrioritized; priorityCodes.Add(code);