Can LightBurn be used as a GCODE generator?

I have a laser that uses proprietary software and firmware that is therefore not directly LightBurn compatible. However, I have found a mechanism by which I send GCODE to the machine. While the software that comes with the laser can produce GCODE, the software is not very powerful and quite clumsy to use. I was wondering if LightBurn could be used as a general GCODE generator? Further are there post processors (or something like) that control the GCODE that gets produced? This machine seems to support (or rather the provided software seems to produce) a slightly non-standard gcode (example below) so I would like to not have to edit them by hand if possible.

G0 Z-16.00
standard
M34 S0
M4 S0
G1 F1000
M19 S1
M18 S0
G0 F10000

(cut start) color=rgb(136,0,255)
G4 P0.1
M104 S0
M4 S1000
M34 S0
G0 F8000
M32 P10
M33 P10
G1 F300
M4 S1000
G0 X-232.745 Y-185.806
G1 X-296.520 Y-186.316
G0 X-296.520 Y-186.316
M4 S0
G0
(cut end)

M4 S0
G4 P0.1
M34 S0
G0 F10000
M6 P1

If I read this literally then the answer is no. LightBurn isn’t a programmable or general gcode generator. It can, however, generate well-formed g-code designed for a variety of controller types including GRBL, Marlin, LinuxCNC, etc.

Nothing built-in or that can be “plugged-into” LightBurn.

Typically for situations like this you could potentially find a line or multiple lines that would need to be swapped with another set. If you were doing this regularly you’d likely want to script something like this or come up with an efficient method of making the edits.

LightBurn does allow for custom static code to be inserted at the start and end of every job. There are no exposed variables as far as I know.

It sounds like it can do what I was hoping and a little python can do that parts that it can’t. I guess my next step to configure the parameters of my machine in LB, do a simple design, see what gcode pops out and compare.

I would suggesting picking a device type in LB that most closely matches what your machine is expecting… or one that makes it easy to edit/add the parts that you need.

You may want to experiment with the various g-code based device types.

Thanks for the suggestion.

After comparing some gcode produce by LightBurn against that produced by my machine software, the first thing I notice is that with the origin in the top left corner my machine software is using negative values for x’s and y’s as opposed to LightBurn using positive values. Is there a way to negate what coordinates LightBurn is using?

Also it would appear that lightburn is using the M106 command for controlling laser power?

G21 ; mm units
G90 ; absolute positioning
; Cut @ 80 mm/sec, 100% power
M8 ; air assist on
M106 S0 ; set fan speed off
G0 X40 Y24 F0 ; move to start postion
; Layer C00
M106 S255 ; set fan speed to 100
G1 Y79 F4800
M9 ; turn off all coolants and air assist
M106 S0 ; turn off all fans
G90 ; absolute positioning
; return to user-defined finish pos
G0 X0 Y0 F0

I want to make sure I understand. What are the coordinates for top-left, top-right, bottom-left, and bottom-right for your machine’s software?

Also, does your machine only work in absolute coordinates or can it also work in a “current position” type of model?

LightBurn always wants to work in a positive coordinate system model irrespective of origin position. So for example if origin was bottom-right, upward and left would be positive values.

No. Not that I’m aware. LightBurn does use negative relative feed coordinates at times but I suspect this is not what you’re asking.

In at least the marlin profile M106/M107 pairs are used to enable/disable laser. S (spindle) is used to set power. Snapmaker profile is similar but uses P for power and is based on a 100% scale.

For example 50mm to the south east of the top left corner appears to be (-50, -50).

G0 X-28.153 Y-22.541
G1 X-28.153 Y-43.991
G1 X-51.603 Y-43.991
G1 X-51.603 Y-22.541
G1 X-28.153 Y-22.541
G0 X-28.153 Y-22.541

That is the gcode moves for a square. So yeah it appears to be absolute only.

I’ll have to output some gcode from LightBurn with the different profiles and look for one that uses M4 for power to match what my machines software does. As I am flying blind here (reverse engineering) I don’t really know the dialect of gcode my machine uses and have to rely on comparing outputs to understand what is going on.

Thanks for all the great input.

Where is 0,0? Top-left?

What were the dimensions of the square? 23.45 x 21.45 mm?

Correct.

The design is long since been lost but it could could have very well have resized the 20mm square I had started with to be the rectangle we see here.

Okay. I find the origin and full negative coordinate system unusual but it could be as simple as swapping all signs for every coordinate. This should work for anything with absolute coords. I initially thought this would be a problem for relative coords but thinking about it again, it may not be an issue.

So I found that the machine has a http interface for sending individual lines of gcode. I am going to experiment with this some and if it works. It shouldn’t take much for me to put together a simple proxy app that acts like networked marlin or grbl machine that translates and forwards on the gcode commands the machine needs. Do you happen to know if those machines I would be emulating take gcode commands from LightBurn line by line or do they get a whole file uploaded and are told to execture?

The normal form of operation is to stream. And is based on a simple serial interface. I’m curious about the http interface because LightBurn recently added the ability to connect via IP for GRBL devices. I understand it as a telnet like interface and defaults to port 23 for connection.

Not sure if this would be easier for you to interface with.

So your current thinking is that you’d basically create a proxy service to act as a GRBL/marlin device which then does 2-way translation on the fly to the http interface provided by your laser? If so, that could be very cool.

If you’re looking for references I know that the Meerk40t application has emulation layers for Ruida and GRBL (or possibly g-code) that does basically the same thing for K40 style controllers. It’s written in Python and is open source although can’t recall the license. Might be something you can leverage.

It is something along the line of a POST to http://ip/cnc/cmd?cmd=

Yes something like that. I do wonder if emulating a LightBurn bridge device would be a route that could work. I suspect that has support for a remote camera and that would give me a hook to facade the http call to capture a frame that my machine supports.

I will take a look.

I suspect this would be far more work. Bridge is not documented and is designed to communicate with Ruida controllers which are not g-code based. I suspect GRBL would be your best bet as it’s well understood, well documented, and well supported. There are precedents for doing g-code over http.

Check out LaserGRBL’s websocket to Serial bridge:
WiFi with ESP8266 – LaserGRBL

Just getting started and not forwarding on any traffic yet. But I have LightBurn convinced enough that there is a GRBL machine there to send it GCODE.

Nice. Are you mimicking a usb serial or network device?

For now network. I would have to actually do something (socat perhaps) with a couple of usb serial ports and cable to support serial as lightburn and this app are running on the same machine.

Have you checked out my experiences with this sort of thing:-
What sort of Gcode options are there?