Skip to main content

gRPC server exposing LinuxCNC machine control and HAL functionality

Project description

linuxcnc-grpc

gRPC interface for LinuxCNC machine control and HAL (Hardware Abstraction Layer).

Why gRPC?

LinuxCNC's native Python API only works locally. This project exposes it over gRPC, enabling:

  • Remote monitoring - Build web dashboards, mobile apps, or desktop GUIs
  • Multi-machine management - Monitor a fleet of CNC machines from one place
  • Any-language integration - Use Go, Node.js, Rust, or any gRPC-supported language
  • Real-time streaming - Subscribe to status updates instead of polling

Running the Server

The server runs on your LinuxCNC machine and exposes the gRPC interface.

Basic Usage

pip install linuxcnc-grpc
# or with uv
uv pip install linuxcnc-grpc
linuxcnc-grpc --host 0.0.0.0 --port 50051

LinuxCNC must already be running before starting the server.

Auto-start with LinuxCNC

To start the gRPC server automatically when LinuxCNC launches, add to your machine's HAL file:

# Start gRPC server (runs until LinuxCNC exits)
loadusr -W linuxcnc-grpc --host 0.0.0.0 --port 50051

Or use a dedicated HAL file via your INI:

[HAL]
POSTGUI_HALFILE = grpc-server.hal

The -W flag tells LinuxCNC to wait for the server to become ready before continuing.

Quick Start

Python

pip install linuxcnc-grpc
import grpc
from linuxcnc_pb import linuxcnc_pb2, linuxcnc_pb2_grpc

channel = grpc.insecure_channel("localhost:50051")
stub = linuxcnc_pb2_grpc.LinuxCNCServiceStub(channel)

status = stub.GetStatus(linuxcnc_pb2.GetStatusRequest())
print(f"Position: X={status.position.x:.3f} Y={status.position.y:.3f} Z={status.position.z:.3f}")

Go

go get github.com/dougcalobrisi/linuxcnc-grpc
import (
    pb "github.com/dougcalobrisi/linuxcnc-grpc/packages/go"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials/insecure"
)

conn, _ := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
client := pb.NewLinuxCNCServiceClient(conn)

status, _ := client.GetStatus(context.Background(), &pb.GetStatusRequest{})
fmt.Printf("Position: X=%.3f Y=%.3f Z=%.3f\n", status.Position.X, status.Position.Y, status.Position.Z)

Node.js / TypeScript

npm install linuxcnc-grpc
import * as grpc from "@grpc/grpc-js";
import { LinuxCNCServiceClient, GetStatusRequest } from "linuxcnc-grpc";

const client = new LinuxCNCServiceClient("localhost:50051", grpc.credentials.createInsecure());

client.getStatus(GetStatusRequest.create(), (err, status) => {
  console.log(`Position: X=${status.position.x.toFixed(3)} Y=${status.position.y.toFixed(3)}`);
});

Rust

[dependencies]
linuxcnc-grpc = "0.5"
tokio = { version = "1", features = ["full"] }
tonic = "0.12"
use linuxcnc_grpc::linuxcnc::linux_cnc_service_client::LinuxCncServiceClient;
use linuxcnc_grpc::linuxcnc::GetStatusRequest;

let mut client = LinuxCncServiceClient::connect("http://localhost:50051").await?;
let status = client.get_status(GetStatusRequest {}).await?.into_inner();
println!("Position: X={:.3} Y={:.3}", status.position.unwrap().x, status.position.unwrap().y);

Examples

Complete examples for all supported languages:

Example Description Python Go Node.js Rust
get_status Poll machine status view view view view
stream_status Real-time status streaming view view view view
jog_axis Jog axes with keyboard view view view view
mdi_command Execute G-code via MDI view view view view
hal_query Query HAL pins/signals view view view view
upload_file Upload, list, delete G-code files view view view view

See examples/README.md for setup instructions.

Services

  • LinuxCNCService - Machine control: status, jogging, MDI, program execution, file management
  • HalService - HAL introspection: query pins, signals, parameters (read-only)

File Management

The server provides UploadFile, ListFiles, and DeleteFile RPCs for remote G-code file management. Files are stored in the NC files directory (default: /home/linuxcnc/linuxcnc/nc_files).

Configure the directory with --nc-files or the LINUXCNC_NC_FILES environment variable:

linuxcnc-grpc --host 0.0.0.0 --nc-files /path/to/nc_files

Safety Warning

This server provides remote control of CNC machinery. Ensure proper safety measures:

  • Use only on trusted networks
  • Implement authentication in production (gRPC supports TLS/mTLS)
  • Never leave machines unattended during remote operation
  • Verify E-stop and safety systems are functional

Production Deployment

For production use, enable TLS authentication:

# Server with TLS
credentials = grpc.ssl_server_credentials([(private_key, certificate)])
server.add_secure_port('[::]:50051', credentials)
# Client with TLS
credentials = grpc.ssl_channel_credentials(root_certificates)
channel = grpc.secure_channel('your-machine:50051', credentials)

See Server Configuration for complete TLS setup instructions.

Development

Requires uv for Python dependency management:

# Install dev dependencies
make setup

# Run tests
make test          # Python tests
make test-all      # All languages

# Generate proto code
make proto-all     # Regenerate for all languages

See CLAUDE.md for detailed development documentation.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linuxcnc_grpc-0.5.0.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linuxcnc_grpc-0.5.0-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

Details for the file linuxcnc_grpc-0.5.0.tar.gz.

File metadata

  • Download URL: linuxcnc_grpc-0.5.0.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for linuxcnc_grpc-0.5.0.tar.gz
Algorithm Hash digest
SHA256 5da883438226b0d7e49e4456aec9fe045af1d023c507ca528dfef5acb8f3697c
MD5 f34e322454823b83c5c7ea494f35a7d5
BLAKE2b-256 d50177a5b47e6b48186ed91f25ad0578a7cd6b3b86a10e73a35a8505ac7a1944

See more details on using hashes here.

File details

Details for the file linuxcnc_grpc-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: linuxcnc_grpc-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for linuxcnc_grpc-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4b72b2e446d27b57094e3ebdf9c40f15184def3f9d1f719d45b9ec93c4a416
MD5 f974da408b4a25aa9ac88efc26c03819
BLAKE2b-256 4a80f0a8735060303be4542e4c83958f884ed9f122337823e88a2af70779d43a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page