cncjs-handwheel 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +231 -8
- package/bin/cncjs-handwheel +349 -30
- package/cncjs-handwheel.config.example.json +40 -0
- package/index.js +311 -62
- package/lib/service.js +109 -8
- package/package.json +6 -3
- package/widget/dist/assets/index-DjeoyRHc.css +1 -0
- package/widget/dist/assets/index-rdV6NzC9.js +40 -0
- package/widget/dist/index.html +13 -0
package/README.md
CHANGED
|
@@ -28,6 +28,9 @@ Create the config (see below), then run it by hand to try it:
|
|
|
28
28
|
- `--usb-port` is optional. It is the USB port the pendant is plugged into, the first `KERNELS` value of
|
|
29
29
|
`udevadm info -a -n /dev/ttyUSBx`. It installs a udev rule that creates `/dev/pendant` and sets up the port so
|
|
30
30
|
that opening it does not reset the ESP32 through its auto-reset circuit. Replug the pendant afterwards.
|
|
31
|
+
- `--bt-mac` and `--bt-channel` are for a Bluetooth pendant instead of a USB one (use one or the other, not both).
|
|
32
|
+
They install a second service that binds the pendant to `/dev/rfcomm0` at boot. See
|
|
33
|
+
[Bluetooth pendant](#bluetooth-pendant-raspberry-pi), which also covers a kernel problem on the Raspberry Pi 4.
|
|
31
34
|
- `sudo env "PATH=$PATH"` keeps an nvm-installed Node visible to root; with a system Node plain `sudo` works.
|
|
32
35
|
- The unit stores the absolute path of the Node that ran the command. After a Node upgrade run `install-service` again.
|
|
33
36
|
- `--dry-run` prints the unit and rule without changing anything.
|
|
@@ -39,26 +42,168 @@ Remove: `sudo env "PATH=$PATH" cncjs-handwheel uninstall-service` (the config fi
|
|
|
39
42
|
curl http://127.0.0.1:8001/status # health
|
|
40
43
|
curl "http://127.0.0.1:8001/log?since=0" # pendant console log
|
|
41
44
|
|
|
45
|
+
## Bluetooth pendant (Raspberry Pi)
|
|
46
|
+
|
|
47
|
+
The pendant can connect over Bluetooth instead of USB. The firmware must offer **Bluetooth Classic serial (SPP)**,
|
|
48
|
+
for example the Arduino `BluetoothSerial` library. A BLE-only device does not work with this method.
|
|
49
|
+
|
|
50
|
+
> **Raspberry Pi 4 kernel warning.** With the Pi 4's **onboard** Bluetooth, **kernel 6.18 cannot pair or connect to the
|
|
51
|
+
> handwheel** (tested with `6.18.60+rpt-rpi-v8`): `btmon` shows `Status: Page Timeout (0x04)` for the connection
|
|
52
|
+
> attempt, `bluetoothctl pair` fails with `ConnectionAttemptFailed`, and `rfcomm connect` fails with `Host is down`.
|
|
53
|
+
> **Kernel 6.12 is required for that particular configuration** (Pi 4, onboard Bluetooth); on 6.12 the same handwheel
|
|
54
|
+
> connects normally. A **USB Bluetooth adapter also works on 6.18**. The cause is the kernel, not the handwheel. `install-service --bt-mac` prints a warning when it sees a 6.18 Raspberry Pi kernel.
|
|
55
|
+
|
|
56
|
+
### Setup
|
|
57
|
+
|
|
58
|
+
1. **Check the kernel.** `uname -r` should show a `6.12.x` kernel if you use the onboard Bluetooth. If apt has installed
|
|
59
|
+
6.18, install a 6.12 kernel image and reboot (see the Raspberry Pi kernel documentation), then check `uname -r` again.
|
|
60
|
+
To stop apt from upgrading it again, hold the kernel packages (check the names with `dpkg -l | grep linux-image`):
|
|
61
|
+
|
|
62
|
+
sudo apt-mark hold linux-image-rpi-v8 linux-headers-rpi-v8
|
|
63
|
+
|
|
64
|
+
A held kernel receives no updates, so remove the hold (`apt-mark unhold`) and retest when a newer kernel is
|
|
65
|
+
out. With a USB adapter on 6.18 you can skip this; disable the onboard controller so there is only one,
|
|
66
|
+
by adding `dtoverlay=disable-bt` to `/boot/firmware/config.txt` and rebooting.
|
|
67
|
+
|
|
68
|
+
2. **Pair the pendant** once, with the pendant switched on and close to the Pi. Stop scanning before you pair; pairing while
|
|
69
|
+
a scan is running makes connection attempts fail:
|
|
70
|
+
|
|
71
|
+
bluetoothctl
|
|
72
|
+
agent on
|
|
73
|
+
default-agent
|
|
74
|
+
scan on # wait for: [NEW] Device AA:BB:CC:DD:EE:FF <pendant name>
|
|
75
|
+
scan off
|
|
76
|
+
pair AA:BB:CC:DD:EE:FF # if asked for a PIN, enter it in this window (often 1234 or 0000)
|
|
77
|
+
trust AA:BB:CC:DD:EE:FF
|
|
78
|
+
quit
|
|
79
|
+
|
|
80
|
+
`Connected: no` after pairing is normal; the connection is made when the bridge opens the port.
|
|
81
|
+
|
|
82
|
+
3. **Install the bindings and the service** (needs `bluez`, which provides `rfcomm`):
|
|
83
|
+
|
|
84
|
+
sudo env "PATH=$PATH" cncjs-handwheel install-service --user <user running CNCjs> --bt-mac AA:BB:CC:DD:EE:FF
|
|
85
|
+
|
|
86
|
+
Use `--bt-channel N` if the serial profile is not on RFCOMM channel 1 (the default and what the ESP32 uses).
|
|
87
|
+
`--dry-run` shows what would be written. This creates `cncjs-handwheel-rfcomm.service`, which runs
|
|
88
|
+
`rfcomm bind 0 <mac> <channel>` at boot, and makes the bridge service start after it.
|
|
89
|
+
|
|
90
|
+
4. **Point the bridge at the port.** In the config set `device.path` to `/dev/rfcomm0`, then
|
|
91
|
+
`sudo systemctl start cncjs-handwheel`.
|
|
92
|
+
|
|
93
|
+
### Notes
|
|
94
|
+
|
|
95
|
+
- **One connection at a time.** The pendant accepts a single Bluetooth client. While the bridge is running it connects
|
|
96
|
+
whenever the pendant is on and in range, so other programs (for example Candle on a PC) cannot use it. Stop the
|
|
97
|
+
service first: `sudo systemctl stop cncjs-handwheel`.
|
|
98
|
+
- **Binding is not connecting.** The binding exists whether or not the pendant is on. The connection is made when the
|
|
99
|
+
bridge opens `/dev/rfcomm0` and it retries every few seconds, so the pendant can be switched on later.
|
|
100
|
+
- **No reset problem.** The USB auto-reset issue (see Troubleshooting) does not exist over Bluetooth; the udev rule
|
|
101
|
+
and `--usb-port` are not needed.
|
|
102
|
+
- **Removing:** `uninstall-service` stops both services and releases `/dev/rfcomm0`.
|
|
103
|
+
|
|
104
|
+
### Troubleshooting Bluetooth
|
|
105
|
+
|
|
106
|
+
- `Page Timeout` / `Host is down` / `ConnectionAttemptFailed`: first check `uname -r` (see the warning above). If the
|
|
107
|
+
kernel is fine, check that no other device is connected to the pendant, move it closer, and look at `sudo btmon` while
|
|
108
|
+
you retry.
|
|
109
|
+
- `rfcomm -a` lists the bindings, `bluetoothctl info AA:BB:CC:DD:EE:FF` shows the pairing state, and
|
|
110
|
+
`journalctl -u cncjs-handwheel-rfcomm -u cncjs-handwheel -f` shows what the services are doing.
|
|
111
|
+
- No `/dev/rfcomm0`: `systemctl status cncjs-handwheel-rfcomm` (is `bluetooth.service` running? is `rfcomm` installed?).
|
|
112
|
+
|
|
42
113
|
## Configuration
|
|
43
114
|
|
|
44
115
|
Precedence, lowest to highest: defaults, the `pendant` section of `~/.cncrc`, `~/.cncjs-handwheel.config`
|
|
45
116
|
(or the file given with `--config`), command line options. CNCjs rewrites `.cncrc` itself, so a separate file is safer.
|
|
46
|
-
Start from `cncjs-
|
|
117
|
+
Start from `cncjs-handwheel.config.example.json`.
|
|
47
118
|
|
|
48
119
|
| Key | Meaning |
|
|
49
120
|
|---|---|
|
|
50
121
|
| `cncjs.port` | CNC controller port as CNCjs knows it (not the pendant) |
|
|
51
122
|
| `cncjs.controllerType` | `Grbl` (Smoothie shares the state format) |
|
|
52
|
-
| `
|
|
123
|
+
| `cncjs.retryInterval` | ms before a failed or lost port open is retried (default 5000, 0 = never) |
|
|
124
|
+
| `cncjs.openTimeout`, `cncjs.maxOpenTries` | ms to wait for CNCjs to answer an open request (5000) and how many unanswered requests are tolerated before the connection to CNCjs is rebuilt (3) |
|
|
125
|
+
| `cncjs.keepaliveMs` | the open request is repeated this often (30000, 0 = off) to verify that CNCjs still has the bridge attached; no answer rebuilds the connection |
|
|
126
|
+
| `cncjs.reopenOnClose` | reopen the CNC port when it is closed behind the bridge's back, e.g. from the CNCjs UI (default `true`). Set `false` if you want the UI's Close to release the machine |
|
|
127
|
+
| `device.path` | pendant serial port: `/dev/pendant` (USB, with the udev rule) or `/dev/rfcomm0` (Bluetooth) |
|
|
53
128
|
| `device.baudRate`, `device.settleMs` | pendant baud rate; pendant input is ignored this long after opening |
|
|
129
|
+
| `device.send` | `false` (or `--no-pendant-send`): never write anything to the pendant, no status, `PONG` or `ERR`. Pendant to CNCjs keeps working. Useful when the firmware does not read from the serial port yet, or to rule the status stream out when debugging |
|
|
54
130
|
| `device.hupcl`, `dtr`, `rts` | modem control line handling (the defaults are fine with the udev rule) |
|
|
55
|
-
| `status.intervalMs`, `status.minGapMs` | status line at least every
|
|
56
|
-
| `status.pollAfterCommand` | ask Grbl for a fresh report after
|
|
131
|
+
| `status.intervalMs`, `status.minGapMs` | status line at least every 400 ms (the heartbeat), and never more often than every 350 ms (about 3 per second); a burst of commands or position changes costs one line per gap, always carrying the latest values. Explicit `?` / `STATUS?` requests are answered at once |
|
|
132
|
+
| `status.pollAfterCommand` | ask Grbl for a fresh report after pendant commands (at most one per `status.minGapMs`) |
|
|
57
133
|
| `status.format` | `grbl` or `json` |
|
|
58
|
-
| `jog.translate` | rewrite jogs like `G21G91X10F500` to `$J=...` so they do not leave Grbl in relative mode |
|
|
134
|
+
| `jog.translate` | rewrite jogs like `G21G91X10F500` to `$J=...` so they do not leave Grbl in relative mode (default `true`; `false` or `--no-jog-translate` sends the pendant's lines as plain gcode, for comparing behavior) |
|
|
135
|
+
| `jog.maxInFlight` | jog governor (default `4`, `0` = off): at most this many gcode lines are handed to CNCjs without an `ok`/`error` reply from Grbl. While the limit is reached, further jogs on the same axis and feed are merged into one longer jog (`Y-0.1` three times becomes `Y-0.3`), opposite jogs cancel out, and the result is sent as soon as a reply frees a slot. The position stays exact; nothing is queued without limit. A different axis or feed replaces the held jog, and a feed hold or reset discards it. This protects Grbl's small serial buffer, which loses characters when a fast wheel outruns it |
|
|
136
|
+
| `jog.cancelSettleMs` | wait between emptying the CNCjs feeder queue and sending the Grbl jog cancel (default 40 ms, see "Jog cancel") |
|
|
137
|
+
| `jog.stallMs` | if the controller acknowledges nothing for this long (default 2000), the unanswered lines are assumed lost: the bridge prints a warning, counts a stall and starts counting afresh |
|
|
138
|
+
| `jog.echo` | tag jog lines with `{echo: false}` as context (default `false`; other gcode is not tagged). CNCjs passes it on in its `serialport:write` event, so a console widget can hide the `feeder> $J=...` echo. Stock CNCjs ignores it (see "Quieting the CNCjs console") |
|
|
59
139
|
| `http` | health endpoint (`enabled`, `host`, `port`) |
|
|
60
140
|
| `log.max` | pendant log lines kept for the widget |
|
|
61
141
|
|
|
142
|
+
## CNCjs widget
|
|
143
|
+
|
|
144
|
+
The package ships a small [custom widget](https://github.com/cncjs/cncjs-widget-boilerplate) for CNCjs (source in
|
|
145
|
+
`widget/`, built output in `widget/dist`). Collapsed, it is one row: a handwheel icon coloured by the link state and a
|
|
146
|
+
short status line. Expanded (fullscreen, or the button in the widget) it adds machine position, handwheel, CNCjs and
|
|
147
|
+
jog statistics and a live tail of the handwheel log.
|
|
148
|
+
|
|
149
|
+
| Icon colour | Meaning |
|
|
150
|
+
|---|---|
|
|
151
|
+
| green | handwheel connected, CNCjs socket up and machine port open |
|
|
152
|
+
| amber | handwheel connected, but CNCjs is unreachable or the machine port is closed |
|
|
153
|
+
| red | handwheel not connected |
|
|
154
|
+
| grey | the widget cannot reach the bridge at all |
|
|
155
|
+
|
|
156
|
+
The widget runs in your browser, not on the Pi, so it cannot use the bridge's `127.0.0.1:8001` directly. Two pieces
|
|
157
|
+
are needed, both on the machine that runs CNCjs.
|
|
158
|
+
|
|
159
|
+
**1. Serve the widget from CNCjs** with its `--mount` option. `cncjs-handwheel --widget-path` prints the directory:
|
|
160
|
+
|
|
161
|
+
cncjs --mount /handwheel:"$(cncjs-handwheel --widget-path)"
|
|
162
|
+
|
|
163
|
+
(Add it to the arguments of your CNCjs service. The path changes when npm updates the package, so keep the
|
|
164
|
+
`$(...)` form or restart CNCjs after an update.)
|
|
165
|
+
|
|
166
|
+
**2. Forward the API through your reverse proxy**, under the same host as CNCjs so there is no CORS or mixed
|
|
167
|
+
content. With Caddy:
|
|
168
|
+
|
|
169
|
+
handle_path /handwheel-api/* {
|
|
170
|
+
reverse_proxy 127.0.0.1:8001
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
The bridge stays on loopback. Anything that reaches that route can read `/status` and `/log` (no secrets, but
|
|
174
|
+
pendant log lines and the machine state), so put it behind the same access control as CNCjs.
|
|
175
|
+
|
|
176
|
+
Then in CNCjs choose *Manage Widgets*, add a *Custom* widget and set its URL to `/handwheel/`.
|
|
177
|
+
|
|
178
|
+
URL parameters (append them to the widget URL, e.g. `/handwheel/?theme=dark`):
|
|
179
|
+
|
|
180
|
+
| Parameter | Default | |
|
|
181
|
+
|---|---|---|
|
|
182
|
+
| `api` | `/handwheel-api` | URL path of the proxied bridge |
|
|
183
|
+
| `theme` | auto | `light` or `dark`; forces the widget's own light or dark colours and stops it from following CNCjs. By default (see below) it follows CNCjs |
|
|
184
|
+
| `mode` | | `full` starts expanded |
|
|
185
|
+
| `debug` | | `1` adds an expand/collapse button (normally the details show only while CNCjs shows the widget fullscreen) |
|
|
186
|
+
| `poll` | `400` | how often the widget asks the bridge, in ms (at least 200) |
|
|
187
|
+
|
|
188
|
+
**Colours.** Served from the same origin as CNCjs, the widget takes its light/dark mode (`data-color-mode` on
|
|
189
|
+
`<html>`) and its colours from CNCjs's own theme tokens (`--color-surface`, `--color-widget-header-bg`,
|
|
190
|
+
`--color-status-danger-text`, ... see `widget/src/hostTheme.js` for the mapping) and follows a mode change live. CNCjs has no green
|
|
191
|
+
token, so the OK green is the widget's own. Where it cannot read the page (cross-origin, such as the Vite dev server) or
|
|
192
|
+
CNCjs lacks a token, the widget's own light and dark stylesheet applies.
|
|
193
|
+
|
|
194
|
+
**Fullscreen.** When the widget is served from the same origin as CNCjs (the setups above), it watches CNCjs's
|
|
195
|
+
widget container and expands and collapses with CNCjs's own fullscreen button; its own expand button then hides.
|
|
196
|
+
Fullscreen, the log pane takes the height that is left, so the CNCjs widget only scrolls when the screen is too short for the cards. This relies on the CSS class CNCjs puts on a fullscreen widget, so a CNCjs refactor can break it; the widget then
|
|
197
|
+
just keeps its own expand button. Where the widget is cross-origin (the Vite dev server) it cannot look at the
|
|
198
|
+
page, so use the expand button or `?mode=full`. A sturdier alternative is `tools/cncjs-custom-widget-fullscreen.diff`
|
|
199
|
+
(11 lines in the CNCjs `Custom` widget): the patched CNCjs posts the fullscreen state to the widget, which listens
|
|
200
|
+
for it in every setup. It is optional.
|
|
201
|
+
|
|
202
|
+
**Developing the widget.** `npm run dev:widget` starts a Vite dev server that forwards `/handwheel-api` to a bridge
|
|
203
|
+
on `127.0.0.1:8001` (override with `HANDWHEEL_BRIDGE=http://host:port`). `npm run build:widget` builds `widget/dist`;
|
|
204
|
+
`npm publish` does that first (`prepublishOnly`), so the published package contains the built widget and the Pi
|
|
205
|
+
needs no build tools.
|
|
206
|
+
|
|
62
207
|
## Pendant protocol
|
|
63
208
|
|
|
64
209
|
Newline-terminated text. Everything except log lines must be printable ASCII.
|
|
@@ -69,25 +214,40 @@ Pendant to bridge:
|
|
|
69
214
|
|---|---|
|
|
70
215
|
| `G21G91X+10F2000` | jog (sent as `$J=...`); any other line is sent to the controller as gcode |
|
|
71
216
|
| `!` / `~` / `^X` (0x18) | feed hold / cycle start / reset, each as a line of its own (reset at most once per 2 s) |
|
|
217
|
+
| `0x85` (the single byte, as a line of its own) or `JOGCANCEL` | cancel the jog in progress (Grbl only), see "Jog cancel" below |
|
|
72
218
|
| `?` or `STATUS?` | immediate status line |
|
|
73
219
|
| `PING` | answered with `PONG` |
|
|
74
220
|
| `; text` | console log entry for the widget; never sent to the controller |
|
|
221
|
+
| `[HW:bat=74,chg=0,eta=13200,st=ok]` | the pendant's own state for the widget, never sent to the controller. `bat` battery 0-100 %, `chg` 1 while charging, `eta` seconds until full (charging) or empty, `st` `ok`, `warn` or `err` (the widget then says "Check log"). Every key is optional (a key left out counts as unknown), unknown keys are ignored. Send it when something changes and at least every 30 s; it is dropped when the pendant disconnects |
|
|
75
222
|
|
|
76
223
|
Bridge to pendant:
|
|
77
224
|
|
|
78
225
|
| Line | Meaning |
|
|
79
226
|
|---|---|
|
|
80
|
-
| `<Idle\|MPos:x,y,z\|WPos:x,y,z\|FS:feed,spindle>` | status
|
|
227
|
+
| `<Idle\|MPos:x,y,z\|WPos:x,y,z\|FS:feed,spindle>` | status: at most about 3 per second, at least every 400 ms, and shortly after every command |
|
|
81
228
|
| `<Disconnected>` | the bridge is up, but CNCjs or the CNC port is not |
|
|
82
229
|
| `ERR:CNCJS_NOT_READY` | a command was dropped because the CNC port is not open |
|
|
83
230
|
| `PONG` | answer to `PING` |
|
|
84
231
|
|
|
85
232
|
The status right after a command shows where the machine was at that moment; Grbl's `ok` only means the move was
|
|
86
|
-
queued. A fresh report follows within a few
|
|
87
|
-
If no line arrives for about
|
|
233
|
+
queued. A fresh report follows within a few hundred milliseconds, and the status stream (about 3 lines per second while
|
|
234
|
+
the machine moves) tracks the move. If no line arrives for about 1 second, treat the bridge as gone.
|
|
88
235
|
|
|
89
236
|
## Troubleshooting
|
|
90
237
|
|
|
238
|
+
- **CNCjs restarted or was down for a while.** The bridge rebuilds its connection by itself (new socket, new access
|
|
239
|
+
token, backoff of 1 to 10 s) and reattaches to the CNC port; the console shows `Disconnected`, `Reconnecting in ...`,
|
|
240
|
+
`Connected to ws://...` and `Connected to port ...`. No restart of the bridge is needed. Nothing is queued while the
|
|
241
|
+
connection is down, so a stale jog is never replayed afterwards.
|
|
242
|
+
- **`Controller did not acknowledge N gcode line(s)`.** Grbl never answered lines CNCjs was given, so they were most
|
|
243
|
+
likely lost on the way (serial buffer overflow, cable or adapter trouble). Jogs are merged and limited by
|
|
244
|
+
`jog.maxInFlight` to avoid this; if it still happens, lower it (try `2`). `/status` shows the counters under `jog`
|
|
245
|
+
(`sent`, `merged`, `discarded`, `stalls`, `inFlight`, `held`).
|
|
246
|
+
- **Commands from the pendant have no effect.** Look for `Dropped pendant command (...)` in the console. It says whether
|
|
247
|
+
the bridge is not connected to CNCjs or the CNC port is not open, and `/status` counts them in
|
|
248
|
+
`cncjs.droppedCommands`. The pendant also receives `ERR:CNCJS_NOT_READY`. If the bridge claims everything is fine but
|
|
249
|
+
CNCjs still ignores commands, the CNCjs log contains `Serial port "..." not accessible`.
|
|
250
|
+
|
|
91
251
|
- **ESP32 reboots or enters download mode when the port is opened.** Linux raises DTR and RTS on the first open, and
|
|
92
252
|
the auto-reset circuit turns that into a reset. Use the udev rule from `--usb-port`. A capacitor of about 1 uF from
|
|
93
253
|
EN to GND on the board removes the problem at its source.
|
|
@@ -95,3 +255,66 @@ If no line arrives for about 500 ms, treat the bridge as gone.
|
|
|
95
255
|
and counted in `/status` (`pendant.garbageLines`); wrong baud rate and a rebooting ESP32 look like that.
|
|
96
256
|
- **`$$` and `$I` output at start.** Normal: CNCjs queries the controller when a client opens the CNC port.
|
|
97
257
|
- **No WPos.** Grbl reports the work offset only every 10-30 status reports; the first WPos can take a few seconds.
|
|
258
|
+
|
|
259
|
+
## Testing without hardware (pendant simulator)
|
|
260
|
+
|
|
261
|
+
`tools/pendant-sim.js` emulates the handwheel on a serial port, so you can exercise the bridge from a dev machine (it lives in the repository only; it is not part of the npm package).
|
|
262
|
+
|
|
263
|
+
Create a virtual serial pair and start the bridge on one end:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
socat -d -d pty,raw,echo=0,link=/tmp/pendant-sim pty,raw,echo=0,link=/tmp/pendant-bridge
|
|
267
|
+
cncjs-handwheel --pendant-port /tmp/pendant-bridge -v
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Then attach the simulator to the other end:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
node tools/pendant-sim.js --port /tmp/pendant-sim
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Interactive keys: arrows = X/Y jog, PgUp/PgDn (or `u`/`j`) = Z jog, `1`-`4` = step 1/0.1/0.01/0.001, `h` = `$H`, space = `!`, `r` = `~`, `X` = Ctrl-X, `?`, `p` = PING, `l` = log line, `b` = burst of jogs in the last direction, `q` = quit. The status line shows state, WPos, tx/rx counters and the age of the last status.
|
|
277
|
+
|
|
278
|
+
Script mode runs unattended and prints a one-line `SUMMARY`:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
node tools/pendant-sim.js --port /tmp/pendant-sim --script "step:0.1, x+*500@500, wait:500, home, hold, resume"
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Tokens: `x+ x- y+ y- z+ z-`, `x+*200@100` (200 jogs at 100/s), `step:N`, `feed:N`, `home hold resume reset status ping cancel`, `log:text`, `raw:LINE`, `wait:MS`.
|
|
285
|
+
|
|
286
|
+
## Quieting the CNCjs console
|
|
287
|
+
|
|
288
|
+
Every line the bridge sends goes through the CNCjs *feeder*, and CNCjs echoes feeder lines in its Console widget as `feeder> ...`
|
|
289
|
+
(lines of a G-code file are not echoed, because the sender never emits `serialport:write`). The bridge tags jogs with
|
|
290
|
+
`{echo: false}` in the command context; CNCjs passes the context along, so the Console widget can skip them with one check in
|
|
291
|
+
`src/app/widgets/Console/index.jsx`:
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
'serialport:write': (data, context) => {
|
|
295
|
+
const { source, __sender__ } = { ...context };
|
|
296
|
+
if (__sender__ === this.senderId) { return; }
|
|
297
|
+
if (context && context.echo === false) { return; } // <- jogs from the handwheel bridge
|
|
298
|
+
...
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Two other sources of console noise can be reduced from the bridge's side:
|
|
302
|
+
- `client> ?` and the `<Jog|MPos...>` reply come from the status request the bridge sends after pendant commands.
|
|
303
|
+
Set `status.pollAfterCommand` to `false`; CNCjs polls the controller by itself and the pendant still gets status lines.
|
|
304
|
+
- The `ok` for every jog is echoed by CNCjs (`serialport:read`); only a console filter can hide those.
|
|
305
|
+
|
|
306
|
+
## Jog cancel
|
|
307
|
+
|
|
308
|
+
For real jogging the pendant sends one long jog when the wheel or button starts (`$J=G21G91X1000F2000`) and a jog cancel when
|
|
309
|
+
it stops. Send the single byte `0x85` followed by a newline (or the text line `JOGCANCEL`). The bridge then
|
|
310
|
+
|
|
311
|
+
1. discards a jog the governor is holding back,
|
|
312
|
+
2. sends CNCjs `feeder:stop`, which empties CNCjs's own queue so no further jog line leaves for Grbl (Grbl's cancel flushes
|
|
313
|
+
only Grbl's planner; jogs still waiting in CNCjs would start again afterwards),
|
|
314
|
+
3. after `jog.cancelSettleMs` sends CNCjs `jogCancel`, which writes the realtime byte `0x85` to Grbl. Grbl acts on `0x85` the
|
|
315
|
+
moment it arrives, ahead of lines still unparsed in its serial buffer, so the short wait lets those be parsed first;
|
|
316
|
+
without it a long jog sent just before the cancel could start after it.
|
|
317
|
+
|
|
318
|
+
Jogs that arrive during that wait are held and released after the cancel. Lines CNCjs had already written to Grbl may still
|
|
319
|
+
run: with the governor that is at most `jog.maxInFlight` short jogs. Jog cancel is Grbl only and needs a CNCjs that knows the
|
|
320
|
+
`jogCancel` command (1.11 or a fork based on it). `/status` counts cancels under `jog.cancels`.
|