This directory contains the CGI server script for handling plot requests from the NC-Edit7 frontend.
The cgiserver.cgi script is a Python CGI script that:
- Lists available CNC machines
- Processes NC programs and generates plot data
- Returns execution results including toolpath segments, variables, and timing
Request:
{
"action": "list_machines"
}Response:
{
"machines": [
{"machineName": "ISO_MILL", "controlType": "MILL"},
{"machineName": "FANUC_T", "controlType": "TURN"},
...
],
"success": true
}Request:
{
"machinedata": [
{
"program": "G90 G54\nG0 X0 Y0 Z10\nG1 X50 Y0 F300\nM30",
"machineName": "ISO_MILL",
"canalNr": "channel-1"
}
]
}Response:
{
"canal": {
"channel-1": {
"segments": [
{
"type": "RAPID",
"lineNumber": 2,
"toolNumber": 1,
"points": [
{"x": 0, "y": 0, "z": 0},
{"x": 0, "y": 0, "z": 10}
]
}
],
"executedLines": [1, 2, 3, 4],
"variables": {},
"timing": [0.1, 0.1, 0.1, 0.1]
}
},
"message": ["Successfully processed ISO_MILL canal channel-1"],
"success": true
}ISO_MILL- ISO standard milling machineFANUC_T- FANUC turning machineSB12RG_F- SB12RG front spindleSB12RG_B- SB12RG back spindleSR20JII_F- SR20JII front spindleSR20JII_B- SR20JII back spindle
-
Enable CGI module:
sudo a2enmod cgi
-
Configure virtual host:
ScriptAlias /ncplot7py/scripts/ /var/www/NC-Edit7/ncplot7py/scripts/ <Directory /var/www/NC-Edit7/ncplot7py/scripts> Options +ExecCGI AddHandler cgi-script .cgi Require all granted </Directory>
-
Make script executable:
chmod +x cgiserver.cgi
Test the CGI script directly:
# List machines
REQUEST_METHOD=POST CONTENT_LENGTH=30 python3 cgiserver.cgi <<EOF
{"action": "list_machines"}
EOF
# Execute program
cat > test.json <<'TESTEOF'
{"machinedata": [{"program": "G0 X0 Y0\nG1 X50 Y0", "machineName": "ISO_MILL", "canalNr": "1"}]}
TESTEOF
REQUEST_METHOD=POST CONTENT_LENGTH=$(wc -c < test.json) python3 cgiserver.cgi < test.jsonThe current implementation is a mock/demo version that:
- Generates simple plot data from basic G-code parsing
- Provides placeholder execution results
- Does not require external dependencies
For production use, this script should be replaced with or extended to:
- Use the actual NC parser from the Python backend
- Integrate with the full CNC state machine
- Support advanced features like tool change detection, synchronization codes, etc.
- Connect to MariaDB for logging (see rebuild-plan.md for environment variables)
For local development with Vite dev server, the dev-cgi-proxy.js plugin handles CGI requests by spawning the Python script.
The script returns error responses with message_TEST field:
{
"error": "Error description",
"message_TEST": ["Detailed error message"]
}