@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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance metrics
|
|
3
|
+
*/
|
|
4
|
+
export interface PerformanceMetrics {
|
|
5
|
+
/** Total response time in milliseconds */
|
|
6
|
+
responseTimeMs: number;
|
|
7
|
+
/** Number of operations performed */
|
|
8
|
+
operations: number;
|
|
9
|
+
/** Number of errors encountered */
|
|
10
|
+
errors: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Format performance metrics for display
|
|
14
|
+
*
|
|
15
|
+
* @param metrics - Performance metrics
|
|
16
|
+
* @returns Formatted string with performance info
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatPerformance(metrics: PerformanceMetrics): string;
|
|
19
|
+
//# sourceMappingURL=performance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.d.ts","sourceRoot":"","sources":["../../../src/formatters/performance.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,cAAc,EAAE,MAAM,CAAA;IACtB,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAiBrE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
/**
|
|
3
|
+
* Format performance metrics for display
|
|
4
|
+
*
|
|
5
|
+
* @param metrics - Performance metrics
|
|
6
|
+
* @returns Formatted string with performance info
|
|
7
|
+
*/
|
|
8
|
+
export function formatPerformance(metrics) {
|
|
9
|
+
const { responseTimeMs, operations, errors } = metrics;
|
|
10
|
+
const lines = [
|
|
11
|
+
chalk.bold('\nPerformance:'),
|
|
12
|
+
` Response time: ${responseTimeMs.toFixed(1)}ms`,
|
|
13
|
+
` Operations: ${operations}`,
|
|
14
|
+
];
|
|
15
|
+
// Highlight errors if present
|
|
16
|
+
if (errors > 0) {
|
|
17
|
+
lines.push(chalk.red(` Errors: ${errors}`));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
lines.push(chalk.green(` Errors: ${errors}`));
|
|
21
|
+
}
|
|
22
|
+
return lines.join('\n');
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=performance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.js","sourceRoot":"","sources":["../../../src/formatters/performance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAczB;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAA2B;IAC3D,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAEtD,MAAM,KAAK,GAAG;QACZ,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC;QAC5B,oBAAoB,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;QACjD,iBAAiB,UAAU,EAAE;KAC9B,CAAA;IAED,8BAA8B;IAC9B,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,MAAM,EAAE,CAAC,CAAC,CAAA;IAC9C,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,MAAM,EAAE,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DataPoint } from '@ya-modbus/driver-types';
|
|
2
|
+
/**
|
|
3
|
+
* Format data point results as a table
|
|
4
|
+
*
|
|
5
|
+
* @param dataPoints - Data point definitions
|
|
6
|
+
* @param values - Data point values (keyed by ID)
|
|
7
|
+
* @returns Formatted table string
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatTable(dataPoints: ReadonlyArray<DataPoint>, values: Record<string, unknown>): string;
|
|
10
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/formatters/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AA0ExD;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,aAAa,CAAC,SAAS,CAAC,EACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAuBR"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import Table from 'cli-table3';
|
|
3
|
+
/**
|
|
4
|
+
* Convert unknown value to string representation
|
|
5
|
+
*
|
|
6
|
+
* @param value - Value to stringify
|
|
7
|
+
* @returns String representation
|
|
8
|
+
*/
|
|
9
|
+
function stringifyValue(value) {
|
|
10
|
+
if (typeof value === 'string') {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
14
|
+
return String(value);
|
|
15
|
+
}
|
|
16
|
+
if (value instanceof Date) {
|
|
17
|
+
return value.toISOString();
|
|
18
|
+
}
|
|
19
|
+
// For objects/arrays, use JSON to avoid '[object Object]'
|
|
20
|
+
return JSON.stringify(value);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Format a value based on data point metadata
|
|
24
|
+
*
|
|
25
|
+
* @param value - Raw value
|
|
26
|
+
* @param dataPoint - Data point definition
|
|
27
|
+
* @returns Formatted string
|
|
28
|
+
*/
|
|
29
|
+
function formatValue(value, dataPoint) {
|
|
30
|
+
// Handle null/undefined
|
|
31
|
+
if (value === null || value === undefined) {
|
|
32
|
+
return chalk.gray('N/A');
|
|
33
|
+
}
|
|
34
|
+
// Format based on type
|
|
35
|
+
switch (dataPoint.type) {
|
|
36
|
+
case 'float': {
|
|
37
|
+
const num = value;
|
|
38
|
+
const decimals = dataPoint.decimals ?? 2;
|
|
39
|
+
return num.toFixed(decimals);
|
|
40
|
+
}
|
|
41
|
+
case 'integer':
|
|
42
|
+
return stringifyValue(value);
|
|
43
|
+
case 'boolean':
|
|
44
|
+
return value ? chalk.green('true') : chalk.red('false');
|
|
45
|
+
case 'enum': {
|
|
46
|
+
if (dataPoint.enumValues) {
|
|
47
|
+
const enumKey = stringifyValue(value);
|
|
48
|
+
return dataPoint.enumValues[enumKey] ?? stringifyValue(value);
|
|
49
|
+
}
|
|
50
|
+
return stringifyValue(value);
|
|
51
|
+
}
|
|
52
|
+
case 'timestamp': {
|
|
53
|
+
if (value instanceof Date) {
|
|
54
|
+
return value.toISOString();
|
|
55
|
+
}
|
|
56
|
+
return stringifyValue(value);
|
|
57
|
+
}
|
|
58
|
+
case 'string':
|
|
59
|
+
return stringifyValue(value);
|
|
60
|
+
default:
|
|
61
|
+
return stringifyValue(value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Format data point results as a table
|
|
66
|
+
*
|
|
67
|
+
* @param dataPoints - Data point definitions
|
|
68
|
+
* @param values - Data point values (keyed by ID)
|
|
69
|
+
* @returns Formatted table string
|
|
70
|
+
*/
|
|
71
|
+
export function formatTable(dataPoints, values) {
|
|
72
|
+
// Create table with headers
|
|
73
|
+
const table = new Table({
|
|
74
|
+
head: [chalk.bold('Data Point'), chalk.bold('Value'), chalk.bold('Unit')],
|
|
75
|
+
style: {
|
|
76
|
+
head: ['cyan'],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
// Add rows for each data point that has a value
|
|
80
|
+
for (const dp of dataPoints) {
|
|
81
|
+
if (!(dp.id in values)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const displayName = dp.name ?? dp.id;
|
|
85
|
+
const formattedValue = formatValue(values[dp.id], dp);
|
|
86
|
+
const unit = dp.unit ?? '';
|
|
87
|
+
table.push([displayName, formattedValue, unit]);
|
|
88
|
+
}
|
|
89
|
+
return table.toString();
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../../src/formatters/table.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAA;IACd,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC5D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IACD,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,WAAW,EAAE,CAAA;IAC5B,CAAC;IACD,0DAA0D;IAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAAc,EAAE,SAAoB;IACvD,wBAAwB;IACxB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,uBAAuB;IACvB,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,OAAO,CAA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KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzE,KAAK,EAAE;YACL,IAAI,EAAE,CAAC,MAAM,CAAC;SACf;KACF,CAAC,CAAA;IAEF,gDAAgD;IAChD,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;QAC5B,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,MAAM,CAAC,EAAE,CAAC;YACvB,SAAQ;QACV,CAAC;QAED,MAAM,WAAW,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAA;QACpC,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;QACrD,MAAM,IAAI,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAA;QAE1B,KAAK,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC,CAAA;IACjD,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAmEnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAqI7B,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { discoverCommand } from './commands/discover.js';
|
|
4
|
+
import { listDevicesCommand } from './commands/list-devices.js';
|
|
5
|
+
import { readCommand } from './commands/read.js';
|
|
6
|
+
import { showDefaultsCommand } from './commands/show-defaults.js';
|
|
7
|
+
import { writeCommand } from './commands/write.js';
|
|
8
|
+
/**
|
|
9
|
+
* Add common connection and driver options to a command
|
|
10
|
+
*
|
|
11
|
+
* @param command - Commander.js command instance
|
|
12
|
+
* @returns The command with connection options added
|
|
13
|
+
*/
|
|
14
|
+
function addConnectionOptions(command) {
|
|
15
|
+
return (command
|
|
16
|
+
// Driver Options
|
|
17
|
+
.optionsGroup('Driver Options:')
|
|
18
|
+
.option('-d, --driver <package>', 'Driver package name (e.g., ya-modbus-driver-xymd1). Use "show-defaults" to see driver config')
|
|
19
|
+
.option('--device <key>', 'Device key for multi-device drivers. Use "list-devices" to see available devices')
|
|
20
|
+
// Connection Options
|
|
21
|
+
.optionsGroup('Connection Options:')
|
|
22
|
+
.requiredOption('-s, --slave-id <id>', 'Modbus slave ID (1-247). May use driver default if available', parseInt)
|
|
23
|
+
.option('--timeout <ms>', 'Response timeout in milliseconds (default: 1000)', parseInt)
|
|
24
|
+
// RTU Connection
|
|
25
|
+
.optionsGroup('RTU Connection (choose this OR TCP):')
|
|
26
|
+
.option('-p, --port <path>', 'Serial port for RTU (e.g., /dev/ttyUSB0, COM3)')
|
|
27
|
+
.option('-b, --baud-rate <rate>', 'Baud rate (RTU only). Uses driver default if not specified', parseInt)
|
|
28
|
+
.option('--parity <type>', 'Parity: none, even, odd (RTU only). Uses driver default if not specified')
|
|
29
|
+
.option('--data-bits <bits>', 'Data bits: 7 or 8 (RTU only). Uses driver default if not specified', parseInt)
|
|
30
|
+
.option('--stop-bits <bits>', 'Stop bits: 1 or 2 (RTU only). Uses driver default if not specified', parseInt)
|
|
31
|
+
// TCP Connection
|
|
32
|
+
.optionsGroup('TCP Connection (choose this OR RTU):')
|
|
33
|
+
.option('-h, --host <host>', 'TCP host for Modbus TCP (e.g., 192.168.1.100)')
|
|
34
|
+
.option('--tcp-port <port>', 'TCP port (default: 502)', parseInt));
|
|
35
|
+
}
|
|
36
|
+
const program = new Command();
|
|
37
|
+
program
|
|
38
|
+
.name('ya-modbus')
|
|
39
|
+
.description('CLI tool for testing and developing Modbus device drivers')
|
|
40
|
+
.version('0.0.0')
|
|
41
|
+
.addHelpText('after', `
|
|
42
|
+
Examples:
|
|
43
|
+
$ ya-modbus read --port /dev/ttyUSB0 --slave-id 1 --driver ya-modbus-driver-xymd1 --all
|
|
44
|
+
$ ya-modbus write --host 192.168.1.100 --slave-id 1 --data-point voltage --value 220
|
|
45
|
+
$ ya-modbus discover --port /dev/ttyUSB0 --strategy quick
|
|
46
|
+
$ ya-modbus show-defaults --driver ya-modbus-driver-xymd1
|
|
47
|
+
`);
|
|
48
|
+
// Device Operations
|
|
49
|
+
program.commandsGroup('Device Operations:');
|
|
50
|
+
// Read command
|
|
51
|
+
addConnectionOptions(program.command('read').description('Read data points from device'))
|
|
52
|
+
.optionsGroup('Data Selection:')
|
|
53
|
+
.option('--data-point <id...>', 'Data point ID(s) to read')
|
|
54
|
+
.option('--all', 'Read all readable data points')
|
|
55
|
+
.optionsGroup('Output Options:')
|
|
56
|
+
.option('-f, --format <type>', 'Output format: table or json (default: table)', 'table')
|
|
57
|
+
.action(async (options) => {
|
|
58
|
+
try {
|
|
59
|
+
// tcpPort is parsed by Commander but not used by readCommand (transport layer handles it).
|
|
60
|
+
// Destructure it out to avoid passing undefined (exactOptionalPropertyTypes requirement).
|
|
61
|
+
const { tcpPort: _tcpPort, ...commandOptions } = options;
|
|
62
|
+
await readCommand(commandOptions);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(`Error: ${error.message}`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
// Write command
|
|
70
|
+
addConnectionOptions(program.command('write').description('Write data point to device'))
|
|
71
|
+
.optionsGroup('Data Options:')
|
|
72
|
+
.requiredOption('--data-point <id>', 'Data point ID to write')
|
|
73
|
+
.requiredOption('--value <value>', 'Value to write')
|
|
74
|
+
.optionsGroup('Write Options:')
|
|
75
|
+
.option('-y, --yes', 'Skip confirmation prompt')
|
|
76
|
+
.option('--verify', 'Read back and verify written value')
|
|
77
|
+
.action(async (options) => {
|
|
78
|
+
try {
|
|
79
|
+
// tcpPort is parsed by Commander but not used by writeCommand (transport layer handles it).
|
|
80
|
+
// Destructure it out to avoid passing undefined (exactOptionalPropertyTypes requirement).
|
|
81
|
+
const { tcpPort: _tcpPort, ...commandOptions } = options;
|
|
82
|
+
await writeCommand(commandOptions);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error(`Error: ${error.message}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
// Device Discovery
|
|
90
|
+
program.commandsGroup('Device Discovery:');
|
|
91
|
+
// Discover command
|
|
92
|
+
program
|
|
93
|
+
.command('discover')
|
|
94
|
+
.description('Discover Modbus devices on serial port by scanning slave IDs and parameters')
|
|
95
|
+
.optionsGroup('Connection:')
|
|
96
|
+
.requiredOption('-p, --port <path>', 'Serial port for RTU (e.g., /dev/ttyUSB0, COM3)')
|
|
97
|
+
.optionsGroup('Driver Options:')
|
|
98
|
+
.option('-d, --driver <package>', 'Driver package (auto-detects from cwd if not specified)')
|
|
99
|
+
.optionsGroup('Discovery Options:')
|
|
100
|
+
.option('--strategy <type>', 'Discovery strategy: quick (driver params) or thorough (all params)', 'quick')
|
|
101
|
+
.option('--timeout <ms>', 'Response timeout in milliseconds (default: 1000)', parseInt)
|
|
102
|
+
.option('--delay <ms>', 'Delay between attempts in milliseconds (default: 100)', parseInt)
|
|
103
|
+
.option('--max-devices <count>', 'Maximum number of devices to find (default: 1, use 0 for unlimited)', parseInt)
|
|
104
|
+
.optionsGroup('Output Options:')
|
|
105
|
+
.option('--verbose', 'Show detailed progress with current parameters being tested')
|
|
106
|
+
.option('--silent', 'Suppress all output except final result (useful for scripts)')
|
|
107
|
+
.option('-f, --format <type>', 'Output format: table or json (default: table)', 'table')
|
|
108
|
+
.action(async (options) => {
|
|
109
|
+
try {
|
|
110
|
+
await discoverCommand(options);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error(`Error: ${error.message}`);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
// Driver Utilities
|
|
118
|
+
program.commandsGroup('Driver Utilities:');
|
|
119
|
+
// List devices command
|
|
120
|
+
program
|
|
121
|
+
.command('list-devices')
|
|
122
|
+
.description('List supported devices from driver DEVICES registry')
|
|
123
|
+
.optionsGroup('Driver Options:')
|
|
124
|
+
.option('-d, --driver <package>', 'Driver package (auto-detects from cwd if not specified)')
|
|
125
|
+
.optionsGroup('Output Options:')
|
|
126
|
+
.option('-f, --format <type>', 'Output format: table or json (default: table)', 'table')
|
|
127
|
+
.action(async (options) => {
|
|
128
|
+
try {
|
|
129
|
+
await listDevicesCommand(options);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.error(`Error: ${error.message}`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
// Show defaults command
|
|
137
|
+
program
|
|
138
|
+
.command('show-defaults')
|
|
139
|
+
.description('Show driver DEFAULT_CONFIG and SUPPORTED_CONFIG')
|
|
140
|
+
.optionsGroup('Driver Options:')
|
|
141
|
+
.option('-d, --driver <package>', 'Driver package (auto-detects from cwd if not specified)')
|
|
142
|
+
.optionsGroup('Output Options:')
|
|
143
|
+
.option('-f, --format <type>', 'Output format: table or json (default: table)', 'table')
|
|
144
|
+
.action(async (options) => {
|
|
145
|
+
try {
|
|
146
|
+
await showDefaultsCommand(options);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error(`Error: ${error.message}`);
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
export { program };
|
|
154
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,eAAe,EAAwB,MAAM,wBAAwB,CAA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,CAAC,OAAO,CAAC,CAAA;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,UAAW,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;QACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC,CAAC,CAAA;AAEJ,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { type LoadedDriver } from '@ya-modbus/driver-loader';
|
|
2
|
+
import type { BaudRate, DataBits, DataPoint, DefaultSerialConfig, DeviceDriver, Parity, StopBits, Transport } from '@ya-modbus/driver-types';
|
|
3
|
+
/**
|
|
4
|
+
* Default RTU transport configuration values
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_RTU_CONFIG: {
|
|
7
|
+
readonly port: "/dev/ttyUSB0";
|
|
8
|
+
readonly baudRate: BaudRate;
|
|
9
|
+
readonly dataBits: DataBits;
|
|
10
|
+
readonly parity: Parity;
|
|
11
|
+
readonly stopBits: StopBits;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Default TCP port for Modbus TCP
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_TCP_PORT = 502;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a data point is readable
|
|
19
|
+
*/
|
|
20
|
+
export declare function isReadable(dataPoint: DataPoint): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a data point is writable
|
|
23
|
+
*/
|
|
24
|
+
export declare function isWritable(dataPoint: DataPoint): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Find a data point by ID
|
|
27
|
+
*
|
|
28
|
+
* @param driver - Device driver instance
|
|
29
|
+
* @param id - Data point ID
|
|
30
|
+
* @returns Data point definition
|
|
31
|
+
* @throws Error if data point not found
|
|
32
|
+
*/
|
|
33
|
+
export declare function findDataPoint(driver: DeviceDriver, id: string): DataPoint;
|
|
34
|
+
/**
|
|
35
|
+
* Find and validate a readable data point
|
|
36
|
+
*
|
|
37
|
+
* @param driver - Device driver instance
|
|
38
|
+
* @param id - Data point ID
|
|
39
|
+
* @returns Data point definition
|
|
40
|
+
* @throws Error if data point not found or not readable
|
|
41
|
+
*/
|
|
42
|
+
export declare function findReadableDataPoint(driver: DeviceDriver, id: string): DataPoint;
|
|
43
|
+
/**
|
|
44
|
+
* Find and validate a writable data point
|
|
45
|
+
*
|
|
46
|
+
* @param driver - Device driver instance
|
|
47
|
+
* @param id - Data point ID
|
|
48
|
+
* @returns Data point definition
|
|
49
|
+
* @throws Error if data point not found or not writable
|
|
50
|
+
*/
|
|
51
|
+
export declare function findWritableDataPoint(driver: DeviceDriver, id: string): DataPoint;
|
|
52
|
+
/**
|
|
53
|
+
* Compare two floating point numbers for approximate equality
|
|
54
|
+
*
|
|
55
|
+
* Uses relative error to handle both very small and very large values correctly.
|
|
56
|
+
* Also checks absolute error to handle values near zero.
|
|
57
|
+
*
|
|
58
|
+
* @param a - First value
|
|
59
|
+
* @param b - Second value
|
|
60
|
+
* @param relativeEpsilon - Relative error tolerance (default: 1e-6, or 0.0001%)
|
|
61
|
+
* @param absoluteEpsilon - Absolute error tolerance for values near zero (default: 1e-9)
|
|
62
|
+
* @returns True if values are approximately equal
|
|
63
|
+
*/
|
|
64
|
+
export declare function floatsEqual(a: number, b: number, relativeEpsilon?: number, absoluteEpsilon?: number): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Parse value string based on data point type
|
|
67
|
+
*/
|
|
68
|
+
export declare function parseValue(valueStr: string, dataPoint: DataPoint): unknown;
|
|
69
|
+
/**
|
|
70
|
+
* Validate value against data point constraints
|
|
71
|
+
*/
|
|
72
|
+
export declare function validateValue(value: unknown, dataPoint: DataPoint): void;
|
|
73
|
+
/**
|
|
74
|
+
* Prompt user for confirmation
|
|
75
|
+
*/
|
|
76
|
+
export declare function confirm(message: string): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Options for creating a transport
|
|
79
|
+
*/
|
|
80
|
+
export interface TransportOptions {
|
|
81
|
+
host?: string;
|
|
82
|
+
port?: string | number;
|
|
83
|
+
baudRate?: number;
|
|
84
|
+
dataBits?: number;
|
|
85
|
+
parity?: string;
|
|
86
|
+
stopBits?: number;
|
|
87
|
+
slaveId: number;
|
|
88
|
+
timeout?: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Options for loading a driver
|
|
92
|
+
*/
|
|
93
|
+
export interface DriverOptions {
|
|
94
|
+
driver?: string;
|
|
95
|
+
device?: string;
|
|
96
|
+
slaveId: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Execute a function with a transport, ensuring cleanup
|
|
100
|
+
*
|
|
101
|
+
* @param options - Transport configuration options
|
|
102
|
+
* @param fn - Function to execute with the transport
|
|
103
|
+
* @returns Result of the function
|
|
104
|
+
*/
|
|
105
|
+
export declare function withTransport<T>(options: TransportOptions, fn: (transport: Transport) => Promise<T>): Promise<T>;
|
|
106
|
+
/**
|
|
107
|
+
* Load driver metadata without creating an instance
|
|
108
|
+
*
|
|
109
|
+
* When no driver name is provided, auto-detects from current working directory.
|
|
110
|
+
*
|
|
111
|
+
* @param driverName - Optional driver package name (auto-detects from cwd if not specified)
|
|
112
|
+
* @returns Loaded driver metadata
|
|
113
|
+
*/
|
|
114
|
+
export declare function loadDriverMetadata(driverName?: string): Promise<LoadedDriver>;
|
|
115
|
+
/**
|
|
116
|
+
* Get the effective default config for a device
|
|
117
|
+
*
|
|
118
|
+
* Returns device-specific config if available, otherwise driver-level config.
|
|
119
|
+
*
|
|
120
|
+
* @param driverMetadata - Loaded driver metadata
|
|
121
|
+
* @param device - Optional device key
|
|
122
|
+
* @returns Effective default config or undefined
|
|
123
|
+
*/
|
|
124
|
+
export declare function getEffectiveDefaultConfig(driverMetadata: LoadedDriver | undefined, device: string | undefined): DefaultSerialConfig | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Get the effective supported config for a device
|
|
127
|
+
*
|
|
128
|
+
* Returns device-specific constraints if available, otherwise driver-level constraints.
|
|
129
|
+
*
|
|
130
|
+
* @param driverMetadata - Loaded driver metadata
|
|
131
|
+
* @param device - Optional device key
|
|
132
|
+
* @returns Effective supported config or undefined
|
|
133
|
+
*/
|
|
134
|
+
export declare function getEffectiveSupportedConfig(driverMetadata: LoadedDriver | undefined, device: string | undefined): LoadedDriver['supportedConfig'] | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Create an effective driver metadata with device-specific configs resolved
|
|
137
|
+
*
|
|
138
|
+
* This creates a view of the driver metadata where defaultConfig and supportedConfig
|
|
139
|
+
* are resolved based on the selected device. This allows validation and other
|
|
140
|
+
* functions to work with device-specific settings transparently.
|
|
141
|
+
*
|
|
142
|
+
* @param driverMetadata - Loaded driver metadata
|
|
143
|
+
* @param device - Optional device key
|
|
144
|
+
* @returns Driver metadata with effective configs for the selected device
|
|
145
|
+
*/
|
|
146
|
+
export declare function getEffectiveDriverMetadata(driverMetadata: LoadedDriver, device: string | undefined): LoadedDriver;
|
|
147
|
+
/**
|
|
148
|
+
* Apply driver defaults to transport options
|
|
149
|
+
*
|
|
150
|
+
* Uses device-specific defaults if a device is selected, otherwise driver-level defaults.
|
|
151
|
+
*
|
|
152
|
+
* @param options - Transport options (may be incomplete)
|
|
153
|
+
* @param driverMetadata - Loaded driver metadata with defaults
|
|
154
|
+
* @param device - Optional device key for multi-device drivers
|
|
155
|
+
* @returns Transport options with defaults applied
|
|
156
|
+
*/
|
|
157
|
+
export declare function applyDriverDefaults(options: TransportOptions, driverMetadata?: LoadedDriver, device?: string): TransportOptions;
|
|
158
|
+
/**
|
|
159
|
+
* Execute a function with a driver instance, ensuring cleanup
|
|
160
|
+
*
|
|
161
|
+
* @param transport - Transport to use for driver communication
|
|
162
|
+
* @param driverMetadata - Loaded driver metadata
|
|
163
|
+
* @param slaveId - Modbus slave ID
|
|
164
|
+
* @param device - Optional device key for multi-device drivers
|
|
165
|
+
* @param fn - Function to execute with the driver
|
|
166
|
+
* @returns Result of the function
|
|
167
|
+
*/
|
|
168
|
+
export declare function withDriverInstance<T>(transport: Transport, driverMetadata: LoadedDriver, slaveId: number, device: string | undefined, fn: (driver: DeviceDriver) => Promise<T>): Promise<T>;
|
|
169
|
+
/**
|
|
170
|
+
* Execute a function with a driver instance, handling the complete workflow
|
|
171
|
+
*
|
|
172
|
+
* This is a convenience function that:
|
|
173
|
+
* 1. Loads driver metadata (DEFAULT_CONFIG, SUPPORTED_CONFIG)
|
|
174
|
+
* 2. Validates user options against driver constraints (SUPPORTED_CONFIG)
|
|
175
|
+
* 3. Applies driver defaults to user options
|
|
176
|
+
* 4. Validates merged options (catches invalid third-party driver defaults)
|
|
177
|
+
* 5. Creates transport with merged configuration
|
|
178
|
+
* 6. Creates driver instance
|
|
179
|
+
* 7. Executes callback with driver and merged options
|
|
180
|
+
* 8. Ensures cleanup (closes transport)
|
|
181
|
+
*
|
|
182
|
+
* @param options - Combined transport and driver options
|
|
183
|
+
* @param fn - Function to execute with the driver (and optionally merged config)
|
|
184
|
+
* @returns Result of the function
|
|
185
|
+
* @throws ValidationError if user options or driver defaults violate constraints
|
|
186
|
+
*/
|
|
187
|
+
export declare function withDriver<T>(options: TransportOptions & {
|
|
188
|
+
driver?: string;
|
|
189
|
+
device?: string;
|
|
190
|
+
}, fn: (driver: DeviceDriver, mergedOptions: TransportOptions) => Promise<T>): Promise<T>;
|
|
191
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../src/utils/commands.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACxE,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,SAAS,EACV,MAAM,yBAAyB,CAAA;AAMhC;;GAEG;AACH,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