@OutsourcedGuru, I was afraid you'd say that, lol! Check out this issue. Basically I learned that spaces could be added or removed anywhere within a valid gcode line and the result is also valid gcode. I'm not sure if every printer can handle this (probably not), but the Taz6 at least could. Also i learned that decimals can include a + (I already took the - into account).
As I tried to take every newly discovered situation into account my regex got crazier and crazier, until I decided to scrap my original code to try another approach. Unfortunately my parser now will likely accept gcode that many machines cannot interpret, but I figure it's better than misreading gcode that the printer CAN handle. I'm sure there are still improvements that can be made, but now I don't need to write any regex if I want to handle a new gcode, I just need to add a new command object to my list of accepted commands. The rest I just ignore.
Here is a command definition I created for G0 which contains the command address, a friendly name, a display template, the accepted parameters and the associated parameter value parsing function. Each paramater also includes a display order used when converting a command object back to a string:
G0 = Command(
"G0",
"Rapid linear move",
"G0 - Linear move to X={X}, Y={Y}, Z={Z}, E={E}, F={F}",
parameters={
"X": CommandParameter("X", CommandParameter.parse_float, 1),
"Y": CommandParameter("Y", CommandParameter.parse_float, 2),
"Z": CommandParameter("Z", CommandParameter.parse_float, 3),
"E": CommandParameter("E", CommandParameter.parse_float, 4),
"F": CommandParameter("F", CommandParameter.parse_float_positive, 5)
}
)
This object is added to a command dictionary and for 'cool running mode' is also added to a list of commands that should have the E parameter stripped. Another list is maintained for commands we want to completely suppress in this mode.
Let me know what you think about this, especially if there are obvious flaws in my logic that I'm overlooking.