Direct read of HPGL

I am using repetier as firmware for a plotter.
I get the data for it in HPGL und convert them external to GCode.
It would be easier if I can use HPGL directly for the plotter.
The idea is to store a HPGL-file on the SD-Card und start with that file.
And interprete the HPGL-File in repetier.

That is the content of the HPGL-File:

the conversion is simple:
IN -> (start no importance)

PU23911,33896 -> (Pen Up) convert to:
G1 X597.77 Y847.4 (the position is devided by 40)

23893,33876 -> (Pen Down) convert to:
G1 X597.32 Y846,9 (values diveded by 40)

Only those 2 commands are of importance PU,PD.
What is the best way to do this?
I see 2 problems:
1) the content is in one line. so the ";" is the separator instead LF and CR.
even worse the ; is the comment-line sign in Gcode!
I am not clear where is the right point in the code...
in gcode.cpp line 442 #if SDSUPPORT sounds promising.
in line 515  if(ch == ';') commentDetected = true; // ignore new data until line end
That covers the ;comments in gcode - which is the HPGL command separator ...

2) is it better to convert PD/PU commands in G1 commands directly after reading it or is it easier
to add PU/PD to the command list??
in gcode.cpp line 496 and following pushCommand(); is this the command to start the print-commands?

Any help is very welcome! thanks


  • First problem is to detect very early that it is no g-code as expected and switch to your own parsing routine inside gcode.cpp parser. If all lines start with IN you could decide on second char that it is HPGL since no GCODE would start like that. Then you also have no problem with max line length of 96 chars.

    Then you need to convert it to gcode and call handlers or reimplement them in your parser.
  • Thanks for your response.
    The IN is the start command and then all commands follow in one line.
    Originally is in the file no LF or CR.
    But this can easily be changed with an editor: ; change to ;\r\n
    So the second character of PU and PD can be used to decide for HPGL.

    Is bool GCode::parseAscii(char *line,bool fromSerial) the right function for conversion?
    (sorry for my poor C++ knowledge... for me it is more try and error)

            case 'P':
            case 'p':
                P = parseLongValue(pos);
                params |= 2048;

    change to:
            //Convert PU23911,33896 to G1 X23911/40 Y33896/40
            case 'P':
            case 'p':
                If (*(pos++) =="U") then  {
                  //G setting
                  params |= 4;}
     Here I have no real glue ! I think I have to rebuild *line to G1 etc??
                //P = parseLongValue(pos);

                //params |= 2048;

  • Ok, having multiple lines and decide in parse and convert to gcode there is also a solution.

    At beginning all params are unset. Then you see the cases where the params get set. It is always adding a bit to a params var plus setting the variable. Just look at the cases how to do this. And return after finishing since the original code goes itself over all vars and you need your code before that happens since you do this on your own.
  • Thanks for help... but my knowledge in C++ is not good enough!
    I finally changed the conversion to the external editor.
    So I have to change the code so mch ...

    I adapted the code only a little bit:
    G0 is with M3,M5 and G1 is without.
    M199 my own new  command:
    M199=0 no conversion
    M199=1 convertToMM: x=x/40 (in HPGL the real position is multiplied by 40!)

    So the convert from HPGL to Gcode is simple:
    PU23911,33896 is changed G0 X23911 Y33896
    PD23911,33896 is changed G1 X23911 Y33896

    Thanks again!
Sign In or Register to comment.