Bidirectional tool table synchronization between LinuxCNC and Smooth tool management system.
A client-side integration that synchronizes tool data between LinuxCNC controllers and a Smooth server, providing:
- Bidirectional sync - Upload tool tables to Smooth, download updates back to LinuxCNC
- Automated sync script - Periodic synchronization via cron or manual trigger
- Automatic backups - Backs up tool table before every sync
- Change detection - Only updates if tool table has changed
- Comprehensive logging - All operations logged with timestamps
- Multiple integration options - Manual, cron-based, HAL, or event-driven
- Parses LinuxCNC tool table (
.tbl) format - Converts to/from Smooth ToolPreset entities
- Preserves all LinuxCNC parameters (T, P, D, Z, X, Y, Q, etc.)
- Round-trip conversion tested
- Machine-specific synchronization
- Configuration file for easy setup
# Python requests library (if not already installed)
pip install requestsCreate ~/.config/smooth/linuxcnc.conf:
# Smooth API configuration
SMOOTH_API_URL="http://localhost:8000"
SMOOTH_API_KEY="your-api-key-here"
# LinuxCNC configuration
LINUXCNC_INI="/home/user/linuxcnc/configs/mill/mill.ini"
# Logging
LOG_DIR="/tmp/smooth-sync"# Manual sync
./sync_tooltable.sh mill01
# Output:
# [2025-10-25 12:00:00] Starting sync for machine: mill01
# [2025-10-25 12:00:00] Tool table: /home/user/linuxcnc/configs/mill/tool.tbl
# [2025-10-25 12:00:00] Backed up tool table to: /tmp/smooth-sync/tool-mill01-20251025-120000.tbl.bak
# [2025-10-25 12:00:01] Parsing tool table...
# [2025-10-25 12:00:01] Uploading tool presets to Smooth...
# [2025-10-25 12:00:02] Upload successful
# [2025-10-25 12:00:02] Downloading tool presets from Smooth...
# [2025-10-25 12:00:03] Converting to LinuxCNC format...
# [2025-10-25 12:00:03] Tool table has changes, updating...
# [2025-10-25 12:00:03] Tool table updated successfully
# [2025-10-25 12:00:03] Sync completed successfully- Locate - Find tool table from LinuxCNC INI file
- Backup - Create timestamped backup before changes
- Parse - Read
.tblfile and extract tool data - Convert - Transform to Smooth ToolPreset format
- Upload - Send to Smooth via REST API (
POST /api/v1/tool-presets)
- Download - Fetch ToolPresets from Smooth (
GET /api/v1/tool-presets?machine_id=...) - Convert - Transform to LinuxCNC format
- Compare - Check if different from current tool table
- Update - Write new tool table only if changed
- Log - Record all operations
T1 P0 D+5.000000 Z-50.000000 ;5mm Drill HSS
T2 P0 D+6.000000 Z-60.000000 X+1.500000 ;6mm Endmill Carbide
T3 P0 D+3.000000 Z-40.000000 ;3mm Probe
T10 P0 D+12.700000 Z-25.000000 ;1/2" Face Mill
- T - Tool number (required)
- P - Pocket number (usually 0)
- D - Diameter (mm or inches)
- Z - Z offset (length)
- X, Y - X, Y offsets (optional)
- U, V, W - Additional offsets for multi-axis (optional)
- Q - Orientation (optional)
- ;comment - Tool description
LinuxCNC entry:
T1 P0 D+5.000000 Z-50.000000 ;5mm Drill HSS
Becomes Smooth ToolPreset:
{
"machine_id": "mill01",
"tool_number": 1,
"description": "5mm Drill HSS",
"offsets": {
"z": -50.0,
"z_unit": "mm"
},
"metadata": {
"source": "linuxcnc",
"diameter": 5.0,
"diameter_unit": "mm",
"pocket": 0
}
}Run sync script when needed:
./sync_tooltable.sh mill01Periodic background sync every 5-15 minutes:
# Edit crontab
crontab -e
# Add line for sync every 5 minutes
*/5 * * * * /path/to/smooth-linuxcnc/sync_tooltable.sh mill01 >> /var/log/smooth-sync.log 2>&1Sync on machine startup/shutdown:
# In your postgui.hal file
loadusr -w /path/to/smooth-linuxcnc/sync_tooltable.sh mill01
Python HAL component that syncs on tool changes:
import hal
import subprocess
h = hal.component("smooth-sync")
h.ready()
# Sync on tool changes
while True:
if tool_changed():
subprocess.run(["/path/to/sync_tooltable.sh", "mill01"])Parses and generates LinuxCNC tool table format.
Functions:
parse_tool_table_line(line)- Parse single tool entryparse_tool_table(content)- Parse complete filegenerate_tool_table_line(tool)- Generate single entrygenerate_tool_table(tools)- Generate complete file
Converts LinuxCNC → Smooth ToolPreset format.
Usage:
./parse_tooltable.py /path/to/tool.tbl machine_idOutput: JSON ready for Smooth API
Converts Smooth ToolPreset → LinuxCNC format.
Usage:
cat presets.json | ./export_tooltable.py -Output: LinuxCNC .tbl format
Orchestrates complete bidirectional sync.
Features:
- Automatic backup before changes
- Change detection (only updates if different)
- Comprehensive logging
- Error handling and rollback
- Configuration file support
# Install pytest
pip install pytest pytest-cov
# Run all tests
pytest tests/
# Run specific test suite
pytest tests/test_translator.py
pytest tests/test_smooth_conversion.py
# With coverage
pytest --cov=. --cov-report=htmlTest coverage: 42+ tests passing
Parse a tool table:
./parse_tooltable.py sample_tool.tbl mill01 | jqGenerate a tool table:
echo '{"items": [{"tool_number": 1, "description": "Test", "metadata": {"diameter": 5.0}}]}' | ./export_tooltable.py -Full sync test:
./sync_tooltable.sh mill01
cat /tmp/smooth-sync/sync-mill01-$(date +%Y%m%d).logLinuxCNC tool tables:
- Defined in machine INI file:
[EMCIO]section,TOOL_TABLEparameter - Common location:
~/linuxcnc/configs/{machine}/tool.tbl
Configuration:
~/.config/smooth/linuxcnc.conf
Logs:
$LOG_DIR/sync-{machine_id}-{date}.log
Backups:
$LOG_DIR/tool-{machine_id}-{timestamp}.tbl.bak
LinuxCNC Controller
│
└─ Tool Table (.tbl file)
│
▼
┌─────────────────────┐
│ Smooth LinuxCNC │
│ (Client-side) │
│ • Parse .tbl │
│ • Convert data │
│ • Sync via API │
└─────────────────────┘
│
▼ REST API
┌─────────────────────┐
│ Smooth Core │
│ (Server) │
│ • ToolPreset │
│ • Version track │
│ • Multi-machine │
└─────────────────────┘
Client-side conversion keeps Smooth Core application-agnostic.
Sync fails with "API key not set":
- Check
~/.config/smooth/linuxcnc.confexists - Verify
SMOOTH_API_KEYis set correctly - Ensure no extra whitespace in config file
Tool table not found:
- Check
LINUXCNC_INIpoints to correct.inifile - Verify INI file has
[EMCIO]section withTOOL_TABLEparameter - Check file permissions
Network errors:
- Verify Smooth server:
curl http://localhost:8000/api/health - Check firewall settings
- Ensure API URL is correct
Tool data mismatch:
- Check unit consistency (mm vs inches in LinuxCNC INI)
- Verify tool table format is correct
- Review sync logs for parsing errors
Permission errors:
- Ensure sync script is executable:
chmod +x sync_tooltable.sh - Check write permissions on tool table file
- Verify log directory exists and is writable
- ✅ Automatic backups - Every sync creates timestamped backup
- ✅ Logging - All operations logged with timestamps
- ✅ Change detection - Only updates when data changes
⚠️ Conflict resolution - Currently last-write-wins⚠️ Network resilience - Add retry logic for unreliable networks⚠️ Notifications - Consider alerting on sync failures⚠️ Monitoring - Set up health checks for cron jobs
See DEVELOPMENT.md for:
- Component architecture details
- LinuxCNC format specification
- Testing procedures
- Contributing guidelines
- DEVELOPMENT.md - Development guide
- ../DEVELOPMENT.md - Cross-project principles
- LinuxCNC Docs - http://linuxcnc.org/docs/html/gcode/tool-compensation.html
Contributions welcome! Please:
- Test with real LinuxCNC configurations
- Ensure round-trip conversion works
- Follow TDD (tests before implementation)
- Update docstrings
- Follow functional programming style
[License information to be added]
- GitHub Issues: [Link to issues]
- LinuxCNC Forum: [Link to thread]
- Documentation: [Link to docs]