Automation With UDP Commands
LightBurn has a network command interface that allows you to launch LightBurn, load a file, run the laser, and perform several other basic operations. It can be used to run commands on the same computer you're using, or on a different networked computer. Some uses for the UDP system include:
- As part of a workflow for generating files in specialized software and sending those files to LightBurn for cutting.
- Loading a file on a different computer used for controlling the laser.
Using UDP¶
LightBurn will listen for UDP commands on the IP address you specify. To communicate with LightBurn on the local computer (the computer you're sending commands from), use localhost (127.0.0.1). To communicate with a separate computer, use the IP address of that computer. LightBurn listens on port 19840 and responds on port 19841. The listener socket should be available on all supported operating systems, but there is an additional Windows-only helper utility called "SendUDP" to simplify launching the software and loading a file.
Using SendUDP¶
SendUDP runs in the command line and can launch the software on the local computer and (optionally) load a file.
Calling "C:\Program Files\LightBurn\SendUDP.exe" "<filename>" will load LightBurn with the specified file, or tell the currently running LightBurn instance to load the file.
Why the quotes?
Because the Program Files folder has a space in the name, it's necessary to put the path to the file in quotes. They can be omitted for files with no spaces in the path, but including them unnecessarily is harmless.
If you're already familiar with the command line, great! If not, here are tips for using SendUDP in both Windows Command Prompt and PowerShell.
Running in Command Prompt:
In Command Prompt, you only need to provide the path to SendUDP.exe followed by the path to your file like in the example below:
"C:\Program Files\LightBurn\SendUDP.exe" "C:\Users\JG\Projects\UDPTest.lbrn2"
Running in PowerShell:
Start with a .\ and use a relative path to SendUDP.exe like in the example below:
.\"..\..\Program Files\LightBurn\SendUDP.exe" "C:\Users\JG\Projects\UDPTest.lbrn2"
Sending UDP Commands¶
Although SendUDP is Windows-only, the listener socket should work on any support operating system. Any method that allows you to communicate with the listener socket should work for sending commands. Our examples will use Python.
Basic Example¶
The example below will command LightBurn to start running the currently open file on the laser.
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # (1)
sock.sendto(b"START", ("127.0.0.1", 19840)) # (2)
- This line configures the script to communicate with the listener socket.
- Change the command from START to one of the other valid commands to perform other actions.
Advanced Example¶
This is a more complete example of using UDP commands in Python, adapted from a post in the
import socket
UDP_IP = "127.0.0.1"
UDP_OUT_PORT = 19840
UDP_IN_PORT = 19841
MESSAGE = b"LOADFILE:F:\\BeeTest.ai" # (1)
# MESSAGE = b"FORCELOAD:F:\\BeeTest.ai"
# MESSAGE = b"IMPORT:F:\\BeeTest.ai"
# MESSAGE = b"LASER:Laser1"
# MESSAGE = b"CLOSE"
# MESSAGE = b"FORCECLOSE"
# MESSAGE = b"START"
# MESSAGE = b"STATUS"
# MESSAGE = b"PING"
print("UDP target IP:", UDP_IP)
print("UDP target port:", UDP_OUT_PORT)
print("UDP input port:", UDP_IN_PORT)
print("message:", MESSAGE)
outSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
inSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
inSock.bind( (UDP_IP, UDP_IN_PORT) )
outSock.sendto(MESSAGE, (UDP_IP, UDP_OUT_PORT))
data, addr = inSock.recvfrom(1024)
print(data, addr)
- The
bbefore the string converts it into a bytes-like object. The socket protocol doesn't accept strings here.
Available UDP Commands¶
All commands will return OK if successful, ! if unsuccessful, or ? if invalid.
STATUS returns ! if the laser is busy and OK if it isn't busy, allowing a script to wait for the laser to finish running.
| Command | Action |
|---|---|
| LOADFILE:<path> | Loads the specified file in the currently open LightBurn window. Do not include <> in the command. |
| FORCELOAD:<path> | Loads the specified file in the currently open LightBurn window, skipping the warning dialog for unsaved changes to the current file. Do not include <> in the command. |
| IMPORT:<path> | Imports the specified file into LightBurn and places it in the center of the workspace. Do not include <> in the command. |
| LASER:<name> | Selects the named laser. |
| CLOSE | Closes LightBurn. |
| FORCECLOSE | Closes LightBurn, skipping the warning dialog for unsaved changes to the current file. |
| START | Starts running the currently open job. |
| STATUS | Checks the status of the laser. Returns OK if the laser is connected and not busy. |
| PING | Checks the status of LightBurn. Returns OK if LightBurn is open and does not have a dialog window open. |
For more help using LightBurn, please visit our forum to talk with LightBurn staff and users, or email support.