Skip to content

Bad parsing of junk GCode #3

@MitchBradley

Description

@MitchBradley

I was testing my new workflow code that synchronizes the UI to the machine state and I ran across the following problem. One of my tests involved erroneous GCode; I wanted to ensure that errors were handled in program order. The erroneous GCode line was:

messed up 

The dataFilter treated that as if it contained the GCode word "M0" and paused the workflow!
I traced the problem down to parser.parseLine(), which returned the following words[] array from that line:

[ 'M0', 'E0', 'S0', 'S0', 'E0', 'D0', 'U0', 'P0' ] 

I believe that a valid GCode word must be a letter followed by a real number, hence there are no valid GCode words in "messed up", so the correct result should be the empty array.

I think the root cause of the problem is in the following regular expression in gcode-parser:parseLine():

const re = /(%.*)|({.*)|((?:\$\$)|(?:\$[a-zA-Z0-9#]*))|([a-zA-Z][0-9\+\-\.]*)|(\*[0-9]+)/igm; 

which should instead be

const re = /(%.*)|({.*)|((?:\$\$)|(?:\$[a-zA-Z0-9#]*))|([a-zA-Z][0-9\+\-\.]+)|(\*[0-9]+)/igm; 

I.e. the subexpression [0-9\+\-\.] should be followed by +, not *, so the numeric suffix is mandatory.

After making this change, my synchronized workflow code behaved properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions