@ya-modbus/cli 0.4.1-refactor-scope-driver-packages.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/CHANGELOG.md +32 -0
- package/LICENSE +674 -0
- package/README.md +612 -0
- package/dist/bin/ya-modbus.d.ts +9 -0
- package/dist/bin/ya-modbus.d.ts.map +1 -0
- package/dist/bin/ya-modbus.js +10 -0
- package/dist/bin/ya-modbus.js.map +1 -0
- package/dist/src/commands/discover.d.ts +25 -0
- package/dist/src/commands/discover.d.ts.map +1 -0
- package/dist/src/commands/discover.js +160 -0
- package/dist/src/commands/discover.js.map +1 -0
- package/dist/src/commands/list-devices.d.ts +21 -0
- package/dist/src/commands/list-devices.d.ts.map +1 -0
- package/dist/src/commands/list-devices.js +75 -0
- package/dist/src/commands/list-devices.js.map +1 -0
- package/dist/src/commands/read.d.ts +25 -0
- package/dist/src/commands/read.d.ts.map +1 -0
- package/dist/src/commands/read.js +76 -0
- package/dist/src/commands/read.js.map +1 -0
- package/dist/src/commands/show-defaults.d.ts +21 -0
- package/dist/src/commands/show-defaults.d.ts.map +1 -0
- package/dist/src/commands/show-defaults.js +48 -0
- package/dist/src/commands/show-defaults.js.map +1 -0
- package/dist/src/commands/write.d.ts +26 -0
- package/dist/src/commands/write.d.ts.map +1 -0
- package/dist/src/commands/write.js +61 -0
- package/dist/src/commands/write.js.map +1 -0
- package/dist/src/discovery/constants.d.ts +37 -0
- package/dist/src/discovery/constants.d.ts.map +1 -0
- package/dist/src/discovery/constants.js +45 -0
- package/dist/src/discovery/constants.js.map +1 -0
- package/dist/src/discovery/device-identifier.d.ts +52 -0
- package/dist/src/discovery/device-identifier.d.ts.map +1 -0
- package/dist/src/discovery/device-identifier.js +193 -0
- package/dist/src/discovery/device-identifier.js.map +1 -0
- package/dist/src/discovery/parameter-generator-utils.d.ts +29 -0
- package/dist/src/discovery/parameter-generator-utils.d.ts.map +1 -0
- package/dist/src/discovery/parameter-generator-utils.js +59 -0
- package/dist/src/discovery/parameter-generator-utils.js.map +1 -0
- package/dist/src/discovery/parameter-generator.d.ts +97 -0
- package/dist/src/discovery/parameter-generator.d.ts.map +1 -0
- package/dist/src/discovery/parameter-generator.js +184 -0
- package/dist/src/discovery/parameter-generator.js.map +1 -0
- package/dist/src/discovery/progress.d.ts +24 -0
- package/dist/src/discovery/progress.d.ts.map +1 -0
- package/dist/src/discovery/progress.js +57 -0
- package/dist/src/discovery/progress.js.map +1 -0
- package/dist/src/discovery/scanner.d.ts +46 -0
- package/dist/src/discovery/scanner.d.ts.map +1 -0
- package/dist/src/discovery/scanner.js +143 -0
- package/dist/src/discovery/scanner.js.map +1 -0
- package/dist/src/formatters/discovery-results.d.ts +10 -0
- package/dist/src/formatters/discovery-results.d.ts.map +1 -0
- package/dist/src/formatters/discovery-results.js +57 -0
- package/dist/src/formatters/discovery-results.js.map +1 -0
- package/dist/src/formatters/json.d.ts +30 -0
- package/dist/src/formatters/json.d.ts.map +1 -0
- package/dist/src/formatters/json.js +33 -0
- package/dist/src/formatters/json.js.map +1 -0
- package/dist/src/formatters/performance.d.ts +19 -0
- package/dist/src/formatters/performance.d.ts.map +1 -0
- package/dist/src/formatters/performance.js +24 -0
- package/dist/src/formatters/performance.js.map +1 -0
- package/dist/src/formatters/table.d.ts +10 -0
- package/dist/src/formatters/table.d.ts.map +1 -0
- package/dist/src/formatters/table.js +91 -0
- package/dist/src/formatters/table.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +154 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/utils/commands.d.ts +191 -0
- package/dist/src/utils/commands.d.ts.map +1 -0
- package/dist/src/utils/commands.js +400 -0
- package/dist/src/utils/commands.js.map +1 -0
- package/dist/src/utils/object-utils.d.ts +20 -0
- package/dist/src/utils/object-utils.d.ts.map +1 -0
- package/dist/src/utils/object-utils.js +28 -0
- package/dist/src/utils/object-utils.js.map +1 -0
- package/dist/src/utils/validation.d.ts +70 -0
- package/dist/src/utils/validation.d.ts.map +1 -0
- package/dist/src/utils/validation.js +158 -0
- package/dist/src/utils/validation.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
# @ya-modbus/cli
|
|
2
|
+
|
|
3
|
+
CLI tool for testing and developing Modbus device drivers.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js >= 18.0.0
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Discover devices** automatically by scanning serial ports for Modbus RTU devices
|
|
12
|
+
- **Read data points** from Modbus devices (RTU/TCP)
|
|
13
|
+
- **Write data points** to Modbus devices with confirmation
|
|
14
|
+
- **List supported devices** from multi-device drivers
|
|
15
|
+
- **Auto-detect drivers** from current package during development
|
|
16
|
+
- **Multiple output formats** (table, JSON)
|
|
17
|
+
- **Performance metrics** (response time, operation count)
|
|
18
|
+
- **Value verification** after writes
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
### Global Installation (Production)
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install -g @ya-modbus/cli
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Local Development
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install --save-dev @ya-modbus/cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
### Read Data Points
|
|
37
|
+
|
|
38
|
+
**Read single data point:**
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# RTU (serial) - uses driver defaults for baud rate, parity, etc.
|
|
42
|
+
ya-modbus read \
|
|
43
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
44
|
+
--port /dev/ttyUSB0 \
|
|
45
|
+
--data-point temperature
|
|
46
|
+
|
|
47
|
+
# TCP
|
|
48
|
+
ya-modbus read \
|
|
49
|
+
--host 192.168.1.100 \
|
|
50
|
+
--slave-id 1 \
|
|
51
|
+
--data-point temperature
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Read multiple data points:**
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Uses driver defaults
|
|
58
|
+
ya-modbus read \
|
|
59
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
60
|
+
--port /dev/ttyUSB0 \
|
|
61
|
+
--data-point temperature humidity
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Read all readable data points:**
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Uses driver defaults
|
|
68
|
+
ya-modbus read \
|
|
69
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
70
|
+
--port /dev/ttyUSB0 \
|
|
71
|
+
--all
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**JSON output:**
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Uses driver defaults
|
|
78
|
+
ya-modbus read \
|
|
79
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
80
|
+
--port /dev/ttyUSB0 \
|
|
81
|
+
--data-point temperature \
|
|
82
|
+
--format json
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Write Data Points
|
|
86
|
+
|
|
87
|
+
**Write with confirmation:**
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Uses driver defaults
|
|
91
|
+
ya-modbus write \
|
|
92
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
93
|
+
--port /dev/ttyUSB0 \
|
|
94
|
+
--data-point setpoint \
|
|
95
|
+
--value 25.5
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Write without confirmation:**
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Uses driver defaults
|
|
102
|
+
ya-modbus write \
|
|
103
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
104
|
+
--port /dev/ttyUSB0 \
|
|
105
|
+
--data-point setpoint \
|
|
106
|
+
--value 25.5 \
|
|
107
|
+
--yes
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Write with verification:**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Uses driver defaults
|
|
114
|
+
ya-modbus write \
|
|
115
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
116
|
+
--port /dev/ttyUSB0 \
|
|
117
|
+
--data-point setpoint \
|
|
118
|
+
--value 25.5 \
|
|
119
|
+
--yes \
|
|
120
|
+
--verify
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Discover Devices
|
|
124
|
+
|
|
125
|
+
**Automatic device discovery** scans a serial port to find Modbus RTU devices by testing different slave IDs and connection parameters.
|
|
126
|
+
|
|
127
|
+
**Quick discovery (uses driver configuration):**
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Discover using driver SUPPORTED_CONFIG to limit parameter combinations
|
|
131
|
+
ya-modbus discover \
|
|
132
|
+
--port /dev/ttyUSB0 \
|
|
133
|
+
--driver @ya-modbus/driver-xymd1
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Discovery without driver (tests common parameters):**
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Tests standard baud rates (9600, 19200) and common parameters
|
|
140
|
+
ya-modbus discover --port /dev/ttyUSB0
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Thorough discovery (tests all parameters):**
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# Tests all standard Modbus parameters (slower but comprehensive)
|
|
147
|
+
ya-modbus discover \
|
|
148
|
+
--port /dev/ttyUSB0 \
|
|
149
|
+
--strategy thorough
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Control number of devices to find:**
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Stop after finding one device (default behavior)
|
|
156
|
+
ya-modbus discover \
|
|
157
|
+
--port /dev/ttyUSB0 \
|
|
158
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
159
|
+
--max-devices 1
|
|
160
|
+
|
|
161
|
+
# Find unlimited devices
|
|
162
|
+
ya-modbus discover \
|
|
163
|
+
--port /dev/ttyUSB0 \
|
|
164
|
+
--max-devices 0
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Silent mode (for scripts):**
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
# Suppress all progress messages, output only results
|
|
171
|
+
ya-modbus discover \
|
|
172
|
+
--port /dev/ttyUSB0 \
|
|
173
|
+
--silent \
|
|
174
|
+
--format json
|
|
175
|
+
|
|
176
|
+
# Example: Extract slave IDs with jq
|
|
177
|
+
devices=$(ya-modbus discover -p /dev/ttyUSB0 --silent -f json | jq '.[].slaveId')
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Verbose progress:**
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
# Show each parameter combination being tested
|
|
184
|
+
ya-modbus discover \
|
|
185
|
+
--port /dev/ttyUSB0 \
|
|
186
|
+
--verbose
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Custom timing:**
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Adjust timeout and delay for specific bus conditions
|
|
193
|
+
ya-modbus discover \
|
|
194
|
+
--port /dev/ttyUSB0 \
|
|
195
|
+
--timeout 100 \
|
|
196
|
+
--delay 50
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Discovery Options:**
|
|
200
|
+
|
|
201
|
+
- `--strategy <type>` - Discovery strategy: `quick` (default) or `thorough`
|
|
202
|
+
- **Quick**: Tests SUPPORTED_CONFIG params or common Modbus parameters
|
|
203
|
+
- **Thorough**: Tests all standard Modbus parameters (8 baud rates, 3 parity modes, 247 addresses)
|
|
204
|
+
- `--driver <package>` - Driver package to use for parameter prioritization (auto-detects from cwd if not specified)
|
|
205
|
+
- `--timeout <ms>` - Response timeout in milliseconds (default: 1000)
|
|
206
|
+
- `--delay <ms>` - Delay between attempts in milliseconds (default: 100)
|
|
207
|
+
- `--max-devices <count>` - Maximum number of devices to find (default: 1, use 0 for unlimited)
|
|
208
|
+
- `--verbose` - Show detailed progress with current parameters being tested
|
|
209
|
+
- `--silent` - Suppress all output except final result (useful for scripts)
|
|
210
|
+
- `--format <type>` - Output format: `table` (default) or `json`
|
|
211
|
+
|
|
212
|
+
**Output Example:**
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
Starting Modbus device discovery on /dev/ttyUSB0...
|
|
216
|
+
Strategy: quick
|
|
217
|
+
Timeout: 1000ms, Delay: 100ms
|
|
218
|
+
|
|
219
|
+
Using driver: @ya-modbus/driver-xymd1
|
|
220
|
+
Using driver SUPPORTED_CONFIG to limit parameter combinations
|
|
221
|
+
|
|
222
|
+
Testing 1482 parameter combinations...
|
|
223
|
+
|
|
224
|
+
✓ Found device: Slave ID 52 @ 9600,N,8,1
|
|
225
|
+
|
|
226
|
+
Discovery complete! Found 1 device(s).
|
|
227
|
+
|
|
228
|
+
┌──────────┬───────────┬────────┬──────────┬──────────┬────────────┬──────────────┐
|
|
229
|
+
│ Slave ID │ Baud Rate │ Parity │ Data Bits│ Stop Bits│ Response │ Supports │
|
|
230
|
+
│ │ │ │ │ │ Time (ms) │ │
|
|
231
|
+
├──────────┼───────────┼────────┼──────────┼──────────┼────────────┼──────────────┤
|
|
232
|
+
│ 52 │ 9600 │ none │ 8 │ 1 │ 45.67 │ FC04 │
|
|
233
|
+
└──────────┴───────────┴────────┴──────────┴──────────┴────────────┴──────────────┘
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Discovery Time Estimates:**
|
|
237
|
+
|
|
238
|
+
Based on real-world testing with default settings (timeout=1000ms, delay=100ms):
|
|
239
|
+
|
|
240
|
+
- **Quick with driver**: ~25 minutes (1,482 combinations typical, ~1.0s per combination)
|
|
241
|
+
- **Quick without driver**: ~50 minutes (2,964 combinations, ~1.0s per combination)
|
|
242
|
+
- **Thorough**: ~6.5 hours (23,712 combinations, ~1.0s per combination)
|
|
243
|
+
|
|
244
|
+
**Performance Tips:**
|
|
245
|
+
|
|
246
|
+
- **Reduce timeout** for faster scans: `--timeout 500` achieves ~0.5s per combination (2x faster)
|
|
247
|
+
- Use `--driver` to prioritize likely parameters and reduce search space
|
|
248
|
+
- Use `--max-devices 1` (default) to stop after finding first device
|
|
249
|
+
- Further reduce `--timeout` if your devices respond quickly (e.g., `--timeout 100` for local devices)
|
|
250
|
+
- Increase `--delay` if you experience bus contention
|
|
251
|
+
|
|
252
|
+
### Connection Options
|
|
253
|
+
|
|
254
|
+
**RTU (Serial):**
|
|
255
|
+
|
|
256
|
+
- `--port <path>` - Serial port (e.g., `/dev/ttyUSB0`, `COM3`)
|
|
257
|
+
- `--baud-rate <rate>` - Baud rate (default: 9600)
|
|
258
|
+
- `--parity <type>` - Parity: none, even, odd (default: even)
|
|
259
|
+
- `--data-bits <bits>` - Data bits: 7 or 8 (default: 8)
|
|
260
|
+
- `--stop-bits <bits>` - Stop bits: 1 or 2 (default: 1)
|
|
261
|
+
|
|
262
|
+
**TCP:**
|
|
263
|
+
|
|
264
|
+
- `--host <host>` - TCP host (IP or hostname)
|
|
265
|
+
- `--tcp-port <port>` - TCP port (default: 502)
|
|
266
|
+
|
|
267
|
+
**Common:**
|
|
268
|
+
|
|
269
|
+
- `--slave-id <id>` - Modbus slave ID (1-247) **(required)**
|
|
270
|
+
- `--timeout <ms>` - Response timeout in milliseconds (default: 1000)
|
|
271
|
+
- `--driver <package>` - Explicit driver package name
|
|
272
|
+
- `--device <key>` - Device key for multi-device drivers (use `list-devices` to see available devices)
|
|
273
|
+
|
|
274
|
+
### Driver Loading
|
|
275
|
+
|
|
276
|
+
**Auto-detect (development mode):**
|
|
277
|
+
|
|
278
|
+
When running from a driver package directory, the CLI auto-detects the driver:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
cd packages/driver-xymd1
|
|
282
|
+
npx ya-modbus read --port /dev/ttyUSB0 --slave-id 1 --data-point temperature
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**Explicit driver (production mode):**
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
ya-modbus read \
|
|
289
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
290
|
+
--port /dev/ttyUSB0 \
|
|
291
|
+
--slave-id 1 \
|
|
292
|
+
--data-point temperature
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Driver Defaults and Validation
|
|
296
|
+
|
|
297
|
+
The CLI automatically uses configuration defaults from driver packages, reducing the number of required options.
|
|
298
|
+
|
|
299
|
+
**Driver-provided defaults:**
|
|
300
|
+
|
|
301
|
+
Drivers export `DEFAULT_CONFIG` and `SUPPORTED_CONFIG` constants that the CLI uses to:
|
|
302
|
+
|
|
303
|
+
- Apply sensible defaults for connection parameters (baud rate, parity, data bits, stop bits, slave ID)
|
|
304
|
+
- Validate user input against device-specific constraints
|
|
305
|
+
- Show helpful error messages with valid values and defaults
|
|
306
|
+
|
|
307
|
+
**Configuration priority** (highest to lowest):
|
|
308
|
+
|
|
309
|
+
1. **User-specified** - Command-line options (e.g., `--baud-rate 19200`)
|
|
310
|
+
2. **Device-specific** - `DEVICES[key].defaultConfig` when `--device` is used
|
|
311
|
+
3. **Driver-level** - `DEFAULT_CONFIG` export from driver package
|
|
312
|
+
4. **CLI fallback** - Built-in defaults (9600 8E1, slave ID 1)
|
|
313
|
+
|
|
314
|
+
The same priority applies to validation constraints (`supportedConfig`).
|
|
315
|
+
|
|
316
|
+
**Before (manual configuration):**
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
ya-modbus read \
|
|
320
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
321
|
+
--port /dev/ttyUSB0 \
|
|
322
|
+
--baud-rate 9600 \
|
|
323
|
+
--parity even \
|
|
324
|
+
--data-bits 8 \
|
|
325
|
+
--stop-bits 1 \
|
|
326
|
+
--slave-id 1 \
|
|
327
|
+
--data-point temperature
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
**After (using driver defaults):**
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# CLI uses driver defaults - just specify port and data point
|
|
334
|
+
ya-modbus read \
|
|
335
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
336
|
+
--port /dev/ttyUSB0 \
|
|
337
|
+
--data-point temperature
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Overriding defaults:**
|
|
341
|
+
|
|
342
|
+
User-specified values always take precedence over driver defaults:
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
# Use driver defaults but override baud rate and slave ID
|
|
346
|
+
ya-modbus read \
|
|
347
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
348
|
+
--port /dev/ttyUSB0 \
|
|
349
|
+
--baud-rate 19200 \
|
|
350
|
+
--slave-id 5 \
|
|
351
|
+
--data-point temperature
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
**Validation:**
|
|
355
|
+
|
|
356
|
+
The CLI validates user input against driver constraints. Invalid values trigger helpful error messages:
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
$ ya-modbus read --driver @ya-modbus/driver-xymd1 --port /dev/ttyUSB0 --baud-rate 115200
|
|
360
|
+
Error: Invalid baud rate 115200. This driver supports: 9600, 14400, 19200 (default: 9600)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
**Backward compatibility:**
|
|
364
|
+
|
|
365
|
+
- Drivers without `DEFAULT_CONFIG` work as before (all parameters required)
|
|
366
|
+
- User-specified values always override defaults
|
|
367
|
+
- TCP connections ignore serial-specific defaults
|
|
368
|
+
|
|
369
|
+
### Working with Third-Party and Development Drivers
|
|
370
|
+
|
|
371
|
+
**⚠️ Important Safety Notes:**
|
|
372
|
+
|
|
373
|
+
The CLI supports loading drivers from:
|
|
374
|
+
|
|
375
|
+
- **First-party drivers** (official `ya-modbus-driver-*` packages)
|
|
376
|
+
- **Third-party drivers** (community/vendor packages)
|
|
377
|
+
- **Development drivers** (local packages under development)
|
|
378
|
+
|
|
379
|
+
When using third-party or development drivers, be aware:
|
|
380
|
+
|
|
381
|
+
1. **Runtime Validation**: The CLI validates driver exports at load time and provides helpful error messages:
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
$ ya-modbus read --driver broken-driver --port /dev/ttyUSB0
|
|
385
|
+
Error: Invalid DEFAULT_CONFIG: baudRate must be a number, got string.
|
|
386
|
+
Fix: export const DEFAULT_CONFIG = { baudRate: 9600, ... } // number, not string
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
2. **Development Mode Hints**: When loading local drivers via auto-detection, invalid configurations trigger detailed fix instructions to help driver developers.
|
|
390
|
+
|
|
391
|
+
3. **Configuration Safety**: Both `DEFAULT_CONFIG` and `SUPPORTED_CONFIG` are validated:
|
|
392
|
+
- Type checking (baudRate must be number, not string)
|
|
393
|
+
- Array validation (validBaudRates must be an array)
|
|
394
|
+
- Range validation (validAddressRange must be [min, max])
|
|
395
|
+
|
|
396
|
+
4. **Merged Validation**: After applying defaults, the CLI validates that `DEFAULT_CONFIG` values comply with `SUPPORTED_CONFIG` constraints. This catches broken third-party driver defaults:
|
|
397
|
+
```bash
|
|
398
|
+
Error: Invalid baud rate 38400. This driver supports: 9600, 14400, 19200 (default: 9600)
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
**Show Driver Defaults:**
|
|
402
|
+
|
|
403
|
+
Use the `show-defaults` command to inspect driver configuration before use:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
# Show defaults from installed driver
|
|
407
|
+
ya-modbus show-defaults --driver @ya-modbus/driver-xymd1
|
|
408
|
+
|
|
409
|
+
# Show defaults from local development driver (auto-detects from cwd)
|
|
410
|
+
cd packages/my-driver
|
|
411
|
+
ya-modbus show-defaults
|
|
412
|
+
|
|
413
|
+
# JSON output for tooling
|
|
414
|
+
ya-modbus show-defaults --driver @ya-modbus/driver-xymd1 --format json
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
Output:
|
|
418
|
+
|
|
419
|
+
```
|
|
420
|
+
Driver Defaults
|
|
421
|
+
===============
|
|
422
|
+
|
|
423
|
+
DEFAULT_CONFIG:
|
|
424
|
+
baudRate: 9600
|
|
425
|
+
parity: "even"
|
|
426
|
+
dataBits: 8
|
|
427
|
+
stopBits: 1
|
|
428
|
+
defaultAddress: 1
|
|
429
|
+
|
|
430
|
+
SUPPORTED_CONFIG:
|
|
431
|
+
validBaudRates: [9600,14400,19200]
|
|
432
|
+
validParity: ["even","none"]
|
|
433
|
+
validDataBits: [8]
|
|
434
|
+
validStopBits: [1]
|
|
435
|
+
validAddressRange: [1,247]
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
**List Supported Devices (Multi-Device Drivers):**
|
|
439
|
+
|
|
440
|
+
Some drivers support multiple device variants (e.g., an energy meter family driver supporting OR-WE-514, OR-WE-516, etc.). Use `list-devices` to see available devices:
|
|
441
|
+
|
|
442
|
+
```bash
|
|
443
|
+
# List devices from installed driver
|
|
444
|
+
ya-modbus list-devices --driver ya-modbus-driver-orno-we
|
|
445
|
+
|
|
446
|
+
# List devices from local development driver (auto-detects from cwd)
|
|
447
|
+
cd packages/my-driver
|
|
448
|
+
ya-modbus list-devices
|
|
449
|
+
|
|
450
|
+
# JSON output for tooling
|
|
451
|
+
ya-modbus list-devices --driver ya-modbus-driver-orno-we --format json
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
Output:
|
|
455
|
+
|
|
456
|
+
```
|
|
457
|
+
Supported Devices
|
|
458
|
+
|
|
459
|
+
┌────────────┬──────────────┬───────────┬─────────────┬─────────────────────────┐
|
|
460
|
+
│ Device │ Manufacturer │ Model │ Config │ Description │
|
|
461
|
+
├────────────┼──────────────┼───────────┼─────────────┼─────────────────────────┤
|
|
462
|
+
│ or-we-514 │ ORNO │ OR-WE-514 │ 9600 8E1 │ Single-phase meter │
|
|
463
|
+
│ or-we-516 │ ORNO │ OR-WE-516 │ 9600 8E1 │ Three-phase meter │
|
|
464
|
+
└────────────┴──────────────┴───────────┴─────────────┴─────────────────────────┘
|
|
465
|
+
|
|
466
|
+
Total: 2 device(s)
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
For single-device drivers, the command indicates there is no DEVICES registry:
|
|
470
|
+
|
|
471
|
+
```
|
|
472
|
+
This driver does not export a DEVICES registry.
|
|
473
|
+
It is a single-device driver.
|
|
474
|
+
|
|
475
|
+
Default config: 9600 8E1
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
**Using Multi-Device Drivers:**
|
|
479
|
+
|
|
480
|
+
When using a multi-device driver, specify the device with `--device`:
|
|
481
|
+
|
|
482
|
+
```bash
|
|
483
|
+
# Read from a specific device variant
|
|
484
|
+
ya-modbus read \
|
|
485
|
+
--driver ya-modbus-driver-orno-we \
|
|
486
|
+
--device or-we-514 \
|
|
487
|
+
--port /dev/ttyUSB0 \
|
|
488
|
+
--data-point voltage
|
|
489
|
+
|
|
490
|
+
# The --device option applies device-specific defaults and validation
|
|
491
|
+
ya-modbus write \
|
|
492
|
+
--driver ya-modbus-driver-orno-we \
|
|
493
|
+
--device or-we-516 \
|
|
494
|
+
--port /dev/ttyUSB0 \
|
|
495
|
+
--data-point relay_state \
|
|
496
|
+
--value 1
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
If `--device` is omitted with a multi-device driver, the driver-level defaults are used. If `--device` is specified with a single-device driver, a warning is shown and the option is ignored.
|
|
500
|
+
|
|
501
|
+
**Best Practices:**
|
|
502
|
+
|
|
503
|
+
1. **Test with `show-defaults`**: Before using a third-party driver, inspect its configuration
|
|
504
|
+
2. **Validate in development**: Run `ya-modbus show-defaults` from your driver directory to validate configuration
|
|
505
|
+
3. **Read error messages**: The CLI provides specific fix instructions for configuration errors
|
|
506
|
+
4. **Use first-party drivers**: Official drivers undergo rigorous validation
|
|
507
|
+
|
|
508
|
+
## Examples
|
|
509
|
+
|
|
510
|
+
### Read temperature from XY-MD1 sensor
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
# Auto-detect driver (from driver package directory) - uses driver defaults
|
|
514
|
+
cd packages/driver-xymd1
|
|
515
|
+
npx ya-modbus read \
|
|
516
|
+
--port /dev/ttyUSB0 \
|
|
517
|
+
--data-point temperature humidity \
|
|
518
|
+
--format table
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
Output:
|
|
522
|
+
|
|
523
|
+
```
|
|
524
|
+
Data Point Value Unit
|
|
525
|
+
────────────────────────────────
|
|
526
|
+
Temperature 24.5 °C
|
|
527
|
+
Humidity 65.2 %
|
|
528
|
+
|
|
529
|
+
Performance:
|
|
530
|
+
Response time: 45ms
|
|
531
|
+
Operations: 2
|
|
532
|
+
Errors: 0
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### Write and verify setpoint
|
|
536
|
+
|
|
537
|
+
```bash
|
|
538
|
+
# Uses driver defaults for baud rate, parity, etc.
|
|
539
|
+
ya-modbus write \
|
|
540
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
541
|
+
--port /dev/ttyUSB0 \
|
|
542
|
+
--data-point device_address \
|
|
543
|
+
--value 5 \
|
|
544
|
+
--yes \
|
|
545
|
+
--verify
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Test TCP connection
|
|
549
|
+
|
|
550
|
+
```bash
|
|
551
|
+
ya-modbus read \
|
|
552
|
+
--host 192.168.1.100 \
|
|
553
|
+
--tcp-port 502 \
|
|
554
|
+
--slave-id 1 \
|
|
555
|
+
--driver @ya-modbus/driver-xymd1 \
|
|
556
|
+
--all \
|
|
557
|
+
--format json
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
## Development
|
|
561
|
+
|
|
562
|
+
### Running Tests
|
|
563
|
+
|
|
564
|
+
```bash
|
|
565
|
+
npm test
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
### Building
|
|
569
|
+
|
|
570
|
+
```bash
|
|
571
|
+
npm run build
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
### Watch Mode
|
|
575
|
+
|
|
576
|
+
```bash
|
|
577
|
+
npm run dev
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
## Troubleshooting
|
|
581
|
+
|
|
582
|
+
### Permission Denied (Linux)
|
|
583
|
+
|
|
584
|
+
Add your user to the `dialout` group:
|
|
585
|
+
|
|
586
|
+
```bash
|
|
587
|
+
sudo usermod -a -G dialout $USER
|
|
588
|
+
# Log out and log back in
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
### Driver Not Found
|
|
592
|
+
|
|
593
|
+
Ensure the driver package is installed:
|
|
594
|
+
|
|
595
|
+
```bash
|
|
596
|
+
npm install @ya-modbus/driver-xymd1
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
Or use auto-detect mode from the driver package directory.
|
|
600
|
+
|
|
601
|
+
### Timeout Errors
|
|
602
|
+
|
|
603
|
+
- Check physical connection (RS-485 termination, wiring)
|
|
604
|
+
- Verify slave ID is correct
|
|
605
|
+
- Try slower baud rate (e.g., 4800)
|
|
606
|
+
- Increase timeout: `--timeout 2000`
|
|
607
|
+
|
|
608
|
+
## See Also
|
|
609
|
+
|
|
610
|
+
- [Driver Development Guide](../../docs/DRIVER-DEVELOPMENT.md)
|
|
611
|
+
- [Architecture Documentation](../../docs/ARCHITECTURE.md)
|
|
612
|
+
- [XYMD1 Driver](../driver-xymd1/README.md)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ya-modbus.d.ts","sourceRoot":"","sources":["../../bin/ya-modbus.ts"],"names":[],"mappings":";AAEA;;;;;GAKG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI entry point
|
|
4
|
+
*
|
|
5
|
+
* This file is the executable entry point that parses command-line arguments.
|
|
6
|
+
* The actual CLI implementation is in src/index.ts
|
|
7
|
+
*/
|
|
8
|
+
import { program } from '../src/index.js';
|
|
9
|
+
program.parse();
|
|
10
|
+
//# sourceMappingURL=ya-modbus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ya-modbus.js","sourceRoot":"","sources":["../../bin/ya-modbus.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC,OAAO,CAAC,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DiscoveryStrategy } from '../discovery/parameter-generator.js';
|
|
2
|
+
/**
|
|
3
|
+
* Discover command options
|
|
4
|
+
*/
|
|
5
|
+
export interface DiscoverOptions {
|
|
6
|
+
port: string;
|
|
7
|
+
strategy?: DiscoveryStrategy;
|
|
8
|
+
driver?: string;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
delay?: number;
|
|
11
|
+
maxDevices?: number;
|
|
12
|
+
verbose?: boolean;
|
|
13
|
+
silent?: boolean;
|
|
14
|
+
format: 'table' | 'json';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Discover command implementation
|
|
18
|
+
*
|
|
19
|
+
* Scans for Modbus RTU devices on the specified port by testing
|
|
20
|
+
* different slave IDs and serial parameters.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Command options
|
|
23
|
+
*/
|
|
24
|
+
export declare function discoverCommand(options: DiscoverOptions): Promise<void>;
|
|
25
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../../src/commands/discover.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AAK5E;;GAEG;AACH,MAAM,WAAW,eAAe;IAE9B,IAAI,EAAE,MAAM,CAAA;IAGZ,QAAQ,CAAC,EAAE,iBAAiB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;IAGhB,MAAM,EAAE,OAAO,GAAG,MAAM,CAAA;CACzB;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAgK7E"}
|