Hello Guest it is July 12, 2025, 12:31:04 AM

Author Topic: Controlling Mach3 via socket connection  (Read 625 times)

0 Members and 1 Guest are viewing this topic.

Controlling Mach3 via socket connection
« on: July 03, 2025, 10:18:54 AM »
I'm working on plugin that allow the control of Mach3 via a socket connect connection were by a API message can be passed to mach3.
I'm using python for the control. I assume it will work with any other program language that can create a connection.

Currently I am able to send and run Gcode and direction XYZ position, read machine positions via the get_dro call. the full is posted at the bottom of the post, some of the api calls are not working properly, I'm slowly working through them.

the reason for building the plugin as I am using my small benchtop mill for for capturing images used for macro photography and image stacking.
I have been using a custom Mcode that that writes and executes a batch script to run a command line image capturing program.

python will give greater control over the image capture and I can generate the gcode on the fly with inputs for custom XYZ step amounts between captures

currently I am having issues finding a nice way to determine if the machine is in motion so to not continue to the next command.
I am using a crude solution of polling the machine positions every 0.1 secs and checking when they are stable.
the IS_MOVING call I can't get to work
any one have a better way or know a direct call I can check for machine status?

Is this something that would be interesting for anyone else?

## Supported Commands
- `GET_DRO <n>`: Get DRO number `n`. Returns `DRO <n> <value>`
- `SET_DRO <n> <value>`: Set DRO number `n` to `value`. Returns `OK`
- `DO_BUTTON <n>`: Press Mach3 button number `n`. Returns `OK`
- `GET_LED <n>`: Get LED number `n`. Returns `LED <n> 1` or `LED <n> 0`
- `SET_LED <n> <0|1>`: Set LED number `n` on/off. Returns `OK`
- `CODE <gcode>`: Run a G-code command (e.g., `CODE G0 X10 Y10`). Returns `OK`
- `MOVE_ABS <axis> <pos>`: Move axis (X/Y/Z/A/B/C) to absolute position. Returns `OK`
- `GET_PARAM <name>`: Get Mach3 parameter by name. Returns `PARAM <name> <value>`
- `SET_PARAM <name> <value>`: Set Mach3 parameter by name. Returns `OK`
- `JOG_ON <axis> <dir> <speed>`: Start jogging axis (dir: 0=neg, 1=pos, speed in units/sec). Returns `OK`
- `JOG_OFF <axis>`: Stop jogging axis. Returns `OK`
- `HOME <axis>`: Home the specified axis. Returns `OK`
- `PROBE`: Start a probe cycle. Returns `OK`
- `SPINDLE_ON`: Start spindle (CW). Returns `OK`
- `SPINDLE_OFF`: Stop spindle. Returns `OK`
- `SET_SPINDLE_SPEED <rpm>`: Set spindle speed. Returns `OK`
- `GET_SPINDLE_SPEED`: Get current spindle speed. Returns `SPINDLE_SPEED <value>`
- `SET_TOOL <tool>`: Set current tool number. Returns `OK`
- `GET_TOOL`: Get current tool number. Returns `TOOL <value>`
- `CYCLE_START`: Start program (cycle start). Returns `OK`
- `FEED_HOLD`: Pause program (feed hold). Returns `OK`
- `STOP`: Stop program. Returns `OK`
- `GET_USER_DRO <n>`: Get user DRO number `n`. Returns `USER_DRO <n> <value>`
- `SET_USER_DRO <n> <value>`: Set user DRO number `n` to `value`. Returns `OK`
- `GET_USER_LED <n>`: Get user LED number `n`. Returns `USER_LED <n> <0|1>`
- `SET_USER_LED <n> <0|1>`: Set user LED number `n` on/off. Returns `OK`
- `GET_INPUT <n>`: Get input signal number `n`. Returns `INPUT <n> <0|1>`
- `SET_OUTPUT <n> <0|1>`: Set output signal number `n` on/off. Returns `OK`
- `IS_MOVING`: Returns `IS_MOVING <0|1>` (1 if machine is moving)
- `IS_STOPPED`: Returns `IS_STOPPED <0|1>` (1 if machine is stopped)
- `SHOW_MESSAGE <text>`: Show a message in Mach3. Returns `OK`



 
« Last Edit: July 03, 2025, 10:20:34 AM by djmickyg »
Re: Controlling Mach3 via socket connection
« Reply #1 on: July 06, 2025, 07:46:18 AM »
doesn't seem like a lot of activity in this plugin section.. anyways

here's the latest update from my project. plugin is doing what I need, half the API calls are a bit flaky. What I need is working. getting axis positions and moving the machine around.

here is my app that automates the the capturing of images at set increments.