Use cases
What you can build on the server, with the RPCs each case uses and the thing to watch out for. Every case shares two facts. The server has no authentication or TLS, so anyone who reaches the port can send any command, even when your own client only reads (see Security considerations). And the status is sampled at an interval, so none of this is a real-time interface.
Dashboards
A dashboard shows the state of one machine or of many: position, the program and its line, feed override and spindle speed, and whether the machine is on. Each machine runs its own server, and the dashboard opens one connection per machine.
It uses StreamStatus for the live values,
GetMachineConfig for the axes, limits
and units, and GetServerInfo to see
whether the server is connected to LinuxCNC. server_instance and connection_id tell a
restarted server or a new connection apart (see
Telling servers and connections apart).
Each open stream holds one server thread for as long as it lasts. With the default settings 26
streams and WaitComplete calls can run at once, and one more fails with RESOURCE_EXHAUSTED
(see Thread pools). Give each dashboard one stream per
machine and share it between its viewers.
Shop-floor monitoring and job alerts
A monitor watches a program run and tells somebody when it ends, pauses or fails, by a chat message, an email or a light. It sends no commands. The job monitor guide has one.
It uses StreamStatus and compares
task.task_state, task.task_mode and task.interp_state from one update to the next. A
finished program and one aborted without an error look the same in the status. A stream that
ends with UNAVAILABLE can carry a reason such as linuxcnc-gone, or none at all (see
Errors and reasons).
StreamErrors adds the text of LinuxCNC’s
error messages, but only where no GUI shows them. Each message goes to one reader, so on a
machine with a GUI such as AXIS a client that reads them takes them away from the operator:
watch the status there instead (see Error messages and the GUI). A
subscriber that falls more than 256 messages behind loses the older ones, and the only sign is
a gap in sequence.
A crashed LinuxCNC is often not detected: the stream keeps sending the last status, so an unchanged status is not proof that the machine is idle (see When LinuxCNC stops).
Job feeds from MES or ERP
A job feed takes the next program from a scheduling system and puts it on the machine, then reports back when the job is done.
It uses UploadFile to write the program into the NC
files directory. Upload each job under a name of its own with fail_if_exists set, so an
upload never replaces a file, least of all the program LinuxCNC has loaded.
ResolveFile says whether a name is the loaded program,
but its answer is a snapshot that another client can outdate, and it does not work while the
server waits for LinuxCNC. Uploads do. SendCommand with program
open loads the file, and the status stream reports the run.
The API also lets a client start the program, with program run_from_line. The program
commands need MODE_AUTO, and the server never switches modes for you (see
Modes and teleop). A feed that stops at the
upload leaves loading and starting to the operator at the machine.
A program started over the network can move the machine while nobody stands at it. Before you build that, read Sending commands and waiting and Stops go first.
RCS_DONEfromSendCommandmeans dispatched, not finished, and aWaitCompletealso answersRCS_DONEonce LinuxCNC has taken a later command from any client, such as an abort. Confirm the result from a fresh status.
Data logging
A logger records values over time, such as spindle speed and load or a temperature pin, in a CSV file or a time-series database. The HAL logging guide has one.
It uses the HAL service, which is read-only. WatchValues sends the changes of up to 1000 named pins, signals and parameters, and QueryPins finds names by pattern. The machine status from StreamStatus carries positions, velocities and the program state.
WatchValues compares the values at an interval, 100 ms by default, so a value that changes
and changes back between two checks is not reported. It sends nothing while nothing changes,
and it sends no first batch with the current values: read them with
GetValue. Use the log for records and trends. A
reaction that has to be fast, such as stopping on a broken tool, belongs in HAL.
Pendants and HMIs
A pendant or a custom panel lets an operator jog, send MDI commands, change overrides and stop, from a tablet, a button box or a screen of your own.
It uses SendCommand with jog, mdi,
feedrate and the stops, StreamStatus
for the display, and
GetMachineConfig for which joint
drives which axis. Jogs and MDI need the right mode first (see
Modes and teleop). The
jog_axis example shows the checks before a jog and the stop on every
way out.
This is the case that can hurt somebody. Keep the machine’s hardware E-stop within reach of whoever holds the pendant: a stop sent through the server is no substitute for it (see What the server cannot do).
A client that has lost the network cannot send the
JOG_STOPthat ends its continuous jog. UseJOG_INCREMENT, which moves a set distance and needs no stop message. If you do useJOG_CONTINUOUS, send the stop on every way out of the program (see Stopping motion on Ctrl+C) and confirm it in the status.
CI against the simulator
A test suite for a client, a post-processor or a job feed can run against LinuxCNC’s simulator instead of a machine. This project tests the server that way: its end-to-end suite runs in GitHub Actions, and locally also in a Docker container, where Debian 13 packages the simulator. End-to-end testing has the commands and the Dockerfile.
Such a suite can use every RPC. A typical test uploads a program with UploadFile, opens and runs it with SendCommand, waits with WaitComplete and checks the status. For tests that need no LinuxCNC at all, the repository has a mock server with a fixed status (see Testing with the mock server).
Never point a test suite that sends commands at a machine with hardware. The tests connect to whatever server answers at the address they are given.