@ya-modbus/device-profiler 0.6.0 → 0.7.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 +10 -0
- package/dist/{bin → cjs/bin}/profile.d.ts.map +1 -1
- package/dist/cjs/bin/profile.js +12 -0
- package/dist/cjs/bin/profile.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/src/cli.d.ts.map +1 -0
- package/dist/cjs/src/cli.js +48 -0
- package/dist/cjs/src/cli.js.map +1 -0
- package/dist/cjs/src/console-formatter.d.ts.map +1 -0
- package/dist/cjs/src/console-formatter.js +58 -0
- package/dist/cjs/src/console-formatter.js.map +1 -0
- package/dist/cjs/src/constants.d.ts.map +1 -0
- package/dist/cjs/src/constants.js +21 -0
- package/dist/cjs/src/constants.js.map +1 -0
- package/dist/cjs/src/error-classifier.d.ts.map +1 -0
- package/dist/cjs/src/error-classifier.js +47 -0
- package/dist/cjs/src/error-classifier.js.map +1 -0
- package/dist/cjs/src/index.d.ts.map +1 -0
- package/dist/cjs/src/index.js +26 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/program.d.ts.map +1 -0
- package/dist/cjs/src/program.js +78 -0
- package/dist/cjs/src/program.js.map +1 -0
- package/dist/cjs/src/read-tester.d.ts.map +1 -0
- package/dist/cjs/src/read-tester.js +56 -0
- package/dist/cjs/src/read-tester.js.map +1 -0
- package/dist/cjs/src/register-scanner.d.ts.map +1 -0
- package/dist/cjs/src/register-scanner.js +71 -0
- package/dist/cjs/src/register-scanner.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/esm/bin/profile.d.ts +9 -0
- package/dist/esm/bin/profile.d.ts.map +1 -0
- package/dist/esm/bin/profile.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/cli.d.ts +27 -0
- package/dist/esm/src/cli.d.ts.map +1 -0
- package/dist/esm/src/cli.js.map +1 -0
- package/dist/esm/src/console-formatter.d.ts +20 -0
- package/dist/esm/src/console-formatter.d.ts.map +1 -0
- package/dist/{src → esm/src}/console-formatter.js +18 -1
- package/dist/esm/src/console-formatter.js.map +1 -0
- package/dist/esm/src/constants.d.ts +18 -0
- package/dist/esm/src/constants.d.ts.map +1 -0
- package/dist/esm/src/constants.js.map +1 -0
- package/dist/esm/src/error-classifier.d.ts +24 -0
- package/dist/esm/src/error-classifier.d.ts.map +1 -0
- package/dist/esm/src/error-classifier.js.map +1 -0
- package/dist/esm/src/index.d.ts +9 -0
- package/dist/esm/src/index.d.ts.map +1 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/program.d.ts +7 -0
- package/dist/esm/src/program.d.ts.map +1 -0
- package/dist/esm/src/program.js.map +1 -0
- package/dist/esm/src/read-tester.d.ts +40 -0
- package/dist/esm/src/read-tester.d.ts.map +1 -0
- package/dist/esm/src/read-tester.js.map +1 -0
- package/dist/esm/src/register-scanner.d.ts +51 -0
- package/dist/esm/src/register-scanner.d.ts.map +1 -0
- package/dist/esm/src/register-scanner.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +26 -9
- package/dist/bin/profile.js.map +0 -1
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js.map +0 -1
- package/dist/src/console-formatter.d.ts.map +0 -1
- package/dist/src/console-formatter.js.map +0 -1
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js.map +0 -1
- package/dist/src/error-classifier.d.ts.map +0 -1
- package/dist/src/error-classifier.js.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/program.d.ts.map +0 -1
- package/dist/src/program.js.map +0 -1
- package/dist/src/read-tester.d.ts.map +0 -1
- package/dist/src/read-tester.js.map +0 -1
- package/dist/src/register-scanner.d.ts.map +0 -1
- package/dist/src/register-scanner.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/dist/{bin → cjs/bin}/profile.d.ts +0 -0
- /package/dist/{src → cjs/src}/cli.d.ts +0 -0
- /package/dist/{src → cjs/src}/console-formatter.d.ts +0 -0
- /package/dist/{src → cjs/src}/constants.d.ts +0 -0
- /package/dist/{src → cjs/src}/error-classifier.d.ts +0 -0
- /package/dist/{src → cjs/src}/index.d.ts +0 -0
- /package/dist/{src → cjs/src}/program.d.ts +0 -0
- /package/dist/{src → cjs/src}/read-tester.d.ts +0 -0
- /package/dist/{src → cjs/src}/register-scanner.d.ts +0 -0
- /package/dist/{bin → esm/bin}/profile.js +0 -0
- /package/dist/{src → esm/src}/cli.js +0 -0
- /package/dist/{src → esm/src}/constants.js +0 -0
- /package/dist/{src → esm/src}/error-classifier.js +0 -0
- /package/dist/{src → esm/src}/index.js +0 -0
- /package/dist/{src → esm/src}/program.js +0 -0
- /package/dist/{src → esm/src}/read-tester.js +0 -0
- /package/dist/{src → esm/src}/register-scanner.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.7.0](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/device-profiler@0.6.0...@ya-modbus/device-profiler@0.7.0) (2026-01-11)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **device-profiler:** display error message instead of [object Object] ([#165](https://github.com/groupsky/ya-modbus/issues/165)) ([591da4e](https://github.com/groupsky/ya-modbus/commit/591da4e889c85593898111c06e0cc633e1f90a29)), closes [#164](https://github.com/groupsky/ya-modbus/issues/164)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **build:** add dual CommonJS/ESM package support ([#187](https://github.com/groupsky/ya-modbus/issues/187)) ([3d78130](https://github.com/groupsky/ya-modbus/commit/3d781304d42edba335cdc320ba25275f3b4ea6c9))
|
|
15
|
+
|
|
6
16
|
# 0.6.0 (2026-01-04)
|
|
7
17
|
|
|
8
18
|
### Bug Fixes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../bin/profile.ts"],"names":[],"mappings":";AAEA;;;;;GAKG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* CLI entry point
|
|
5
|
+
*
|
|
6
|
+
* This file is the executable entry point that parses command-line arguments.
|
|
7
|
+
* The actual CLI implementation is in src/program.ts
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const program_js_1 = require("../src/program.js");
|
|
11
|
+
program_js_1.program.parse();
|
|
12
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../bin/profile.ts"],"names":[],"mappings":";;AAEA;;;;;GAKG;;AAEH,kDAA2C;AAE3C,oBAAO,CAAC,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAG/C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,uBAAuB;IACvB,SAAS,EAAE,SAAS,CAAA;IACpB,4BAA4B;IAC5B,IAAI,EAAE,YAAY,CAAA;IAClB,gCAAgC;IAChC,YAAY,EAAE,MAAM,CAAA;IACpB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAA;IAClB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC/E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CLI orchestrator for register scanning
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runProfileScan = runProfileScan;
|
|
7
|
+
const console_formatter_js_1 = require("./console-formatter.js");
|
|
8
|
+
const constants_js_1 = require("./constants.js");
|
|
9
|
+
const register_scanner_js_1 = require("./register-scanner.js");
|
|
10
|
+
/**
|
|
11
|
+
* Run a register profile scan with console output
|
|
12
|
+
*
|
|
13
|
+
* @param options - Scan configuration
|
|
14
|
+
*/
|
|
15
|
+
async function runProfileScan(options) {
|
|
16
|
+
const { transport, type, startAddress, endAddress, batchSize } = options;
|
|
17
|
+
const results = [];
|
|
18
|
+
try {
|
|
19
|
+
console.log(`Scanning ${type} registers from ${startAddress} to ${endAddress}...`);
|
|
20
|
+
console.log();
|
|
21
|
+
let lastProgressUpdate = 0;
|
|
22
|
+
await (0, register_scanner_js_1.scanRegisters)({
|
|
23
|
+
transport,
|
|
24
|
+
type,
|
|
25
|
+
startAddress,
|
|
26
|
+
endAddress,
|
|
27
|
+
...(batchSize !== undefined && { batchSize }),
|
|
28
|
+
onProgress: (current, total) => {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
if (now - lastProgressUpdate >= constants_js_1.PROGRESS_UPDATE_INTERVAL_MS || current === total) {
|
|
31
|
+
process.stdout.write(`\r${(0, console_formatter_js_1.formatProgress)(current, total)}`);
|
|
32
|
+
lastProgressUpdate = now;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
onResult: (result) => {
|
|
36
|
+
results.push(result);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
console.log('\n');
|
|
40
|
+
console.log('Scan complete!');
|
|
41
|
+
console.log();
|
|
42
|
+
console.log((0, console_formatter_js_1.formatSummary)(results));
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
await transport.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA8BH,wCAkCC;AA5DD,iEAAsE;AACtE,iDAA4D;AAE5D,+DAAsE;AAkBtE;;;;GAIG;AACI,KAAK,UAAU,cAAc,CAAC,OAA2B;IAC9D,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IACxE,MAAM,OAAO,GAAiB,EAAE,CAAA;IAEhC,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,mBAAmB,YAAY,OAAO,UAAU,KAAK,CAAC,CAAA;QAClF,OAAO,CAAC,GAAG,EAAE,CAAA;QAEb,IAAI,kBAAkB,GAAG,CAAC,CAAA;QAC1B,MAAM,IAAA,mCAAa,EAAC;YAClB,SAAS;YACT,IAAI;YACJ,YAAY;YACZ,UAAU;YACV,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;YAC7C,UAAU,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;gBAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;gBACtB,IAAI,GAAG,GAAG,kBAAkB,IAAI,0CAA2B,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;oBACjF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,IAAA,qCAAc,EAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,CAAA;oBAC3D,kBAAkB,GAAG,GAAG,CAAA;gBAC1B,CAAC;YACH,CAAC;YACD,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;gBACnB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACtB,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACjB,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;QAC7B,OAAO,CAAC,GAAG,EAAE,CAAA;QACb,OAAO,CAAC,GAAG,CAAC,IAAA,oCAAa,EAAC,OAAO,CAAC,CAAC,CAAA;IACrC,CAAC;YAAS,CAAC;QACT,MAAM,SAAS,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-formatter.d.ts","sourceRoot":"","sources":["../../../src/console-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAevD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGrE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAiB3D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Console output formatting for register scanning
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatProgress = formatProgress;
|
|
7
|
+
exports.formatSummary = formatSummary;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const cli_table3_1 = tslib_1.__importDefault(require("cli-table3"));
|
|
10
|
+
function formatError(error) {
|
|
11
|
+
if (error == null)
|
|
12
|
+
return '-';
|
|
13
|
+
if (typeof error === 'string')
|
|
14
|
+
return error;
|
|
15
|
+
if (error instanceof Error)
|
|
16
|
+
return error.message;
|
|
17
|
+
if (typeof error === 'object' && 'message' in error)
|
|
18
|
+
return String(error.message);
|
|
19
|
+
try {
|
|
20
|
+
return JSON.stringify(error);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Fallback for circular references or BigInt - return type name
|
|
24
|
+
return `[${typeof error}]`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Format progress message
|
|
29
|
+
*
|
|
30
|
+
* @param current - Current count
|
|
31
|
+
* @param total - Total count
|
|
32
|
+
* @returns Formatted progress string
|
|
33
|
+
*/
|
|
34
|
+
function formatProgress(current, total) {
|
|
35
|
+
const percentage = total > 0 ? Math.round((current / total) * 100) : 0;
|
|
36
|
+
return `Progress: ${current}/${total} (${percentage}%)`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Format summary table of scan results
|
|
40
|
+
*
|
|
41
|
+
* @param results - Scan results
|
|
42
|
+
* @returns Formatted table string
|
|
43
|
+
*/
|
|
44
|
+
function formatSummary(results) {
|
|
45
|
+
const table = new cli_table3_1.default({
|
|
46
|
+
head: ['Address', 'Type', 'Status', 'Value', 'Timing (ms)', 'Error'],
|
|
47
|
+
style: { head: [] },
|
|
48
|
+
});
|
|
49
|
+
for (const result of results) {
|
|
50
|
+
const value = result.success && result.value ? result.value.toString('hex').toUpperCase() : '-';
|
|
51
|
+
const status = result.success ? 'OK' : 'FAIL';
|
|
52
|
+
const error = formatError(result.error);
|
|
53
|
+
const timing = result.timing.toFixed(1);
|
|
54
|
+
table.push([result.address.toString(), result.type, status, value, timing, error]);
|
|
55
|
+
}
|
|
56
|
+
return table.toString();
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=console-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-formatter.js","sourceRoot":"","sources":["../../../src/console-formatter.ts"],"names":[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CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;QAE/F,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAA;QAC7C,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;QAEvC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;IACpF,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oCAAoC;AACpC,eAAO,MAAM,QAAQ,IAAI,CAAA;AAEzB,oCAAoC;AACpC,eAAO,MAAM,QAAQ,QAAQ,CAAA;AAE7B,oCAAoC;AACpC,eAAO,MAAM,YAAY,IAAI,CAAA;AAE7B,oCAAoC;AACpC,eAAO,MAAM,YAAY,MAAM,CAAA;AAE/B,4CAA4C;AAC5C,eAAO,MAAM,kBAAkB,KAAK,CAAA;AAEpC,0CAA0C;AAC1C,eAAO,MAAM,kBAAkB,IAAI,CAAA;AAEnC,gEAAgE;AAChE,eAAO,MAAM,2BAA2B,MAAM,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Constants for Modbus device profiling
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PROGRESS_UPDATE_INTERVAL_MS = exports.BYTES_PER_REGISTER = exports.DEFAULT_BATCH_SIZE = exports.MAX_SLAVE_ID = exports.MIN_SLAVE_ID = exports.MAX_PORT = exports.MIN_PORT = void 0;
|
|
7
|
+
/** Minimum valid TCP port number */
|
|
8
|
+
exports.MIN_PORT = 1;
|
|
9
|
+
/** Maximum valid TCP port number */
|
|
10
|
+
exports.MAX_PORT = 65535;
|
|
11
|
+
/** Minimum valid Modbus slave ID */
|
|
12
|
+
exports.MIN_SLAVE_ID = 1;
|
|
13
|
+
/** Maximum valid Modbus slave ID */
|
|
14
|
+
exports.MAX_SLAVE_ID = 247;
|
|
15
|
+
/** Default batch size for register reads */
|
|
16
|
+
exports.DEFAULT_BATCH_SIZE = 10;
|
|
17
|
+
/** Number of bytes per Modbus register */
|
|
18
|
+
exports.BYTES_PER_REGISTER = 2;
|
|
19
|
+
/** Minimum interval between progress updates in milliseconds */
|
|
20
|
+
exports.PROGRESS_UPDATE_INTERVAL_MS = 100;
|
|
21
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oCAAoC;AACvB,QAAA,QAAQ,GAAG,CAAC,CAAA;AAEzB,oCAAoC;AACvB,QAAA,QAAQ,GAAG,KAAK,CAAA;AAE7B,oCAAoC;AACvB,QAAA,YAAY,GAAG,CAAC,CAAA;AAE7B,oCAAoC;AACvB,QAAA,YAAY,GAAG,GAAG,CAAA;AAE/B,4CAA4C;AAC/B,QAAA,kBAAkB,GAAG,EAAE,CAAA;AAEpC,0CAA0C;AAC7B,QAAA,kBAAkB,GAAG,CAAC,CAAA;AAEnC,gEAAgE;AACnD,QAAA,2BAA2B,GAAG,GAAG,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-classifier.d.ts","sourceRoot":"","sources":["../../../src/error-classifier.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,oBAAY,SAAS;IACnB,0BAA0B;IAC1B,OAAO,YAAY;IACnB,wCAAwC;IACxC,GAAG,QAAQ;IACX,+CAA+C;IAC/C,eAAe,qBAAqB;IACpC,oCAAoC;IACpC,OAAO,YAAY;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAwBrD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error classification for Modbus operations
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ErrorType = void 0;
|
|
7
|
+
exports.classifyError = classifyError;
|
|
8
|
+
/**
|
|
9
|
+
* Modbus error types
|
|
10
|
+
*/
|
|
11
|
+
var ErrorType;
|
|
12
|
+
(function (ErrorType) {
|
|
13
|
+
/** Operation timed out */
|
|
14
|
+
ErrorType["Timeout"] = "timeout";
|
|
15
|
+
/** CRC or checksum validation failed */
|
|
16
|
+
ErrorType["CRC"] = "crc";
|
|
17
|
+
/** Modbus exception code returned by device */
|
|
18
|
+
ErrorType["ModbusException"] = "modbus_exception";
|
|
19
|
+
/** Unknown or unclassified error */
|
|
20
|
+
ErrorType["Unknown"] = "unknown";
|
|
21
|
+
})(ErrorType || (exports.ErrorType = ErrorType = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Classify a Modbus error by examining its message and properties
|
|
24
|
+
*
|
|
25
|
+
* @param error - Error to classify
|
|
26
|
+
* @returns Error classification
|
|
27
|
+
*/
|
|
28
|
+
function classifyError(error) {
|
|
29
|
+
const message = error.message?.toLowerCase() ?? '';
|
|
30
|
+
const code = error.code;
|
|
31
|
+
// Check for timeout
|
|
32
|
+
if (message.includes('timeout') || message.includes('timed out') || code === 'ETIMEDOUT') {
|
|
33
|
+
return ErrorType.Timeout;
|
|
34
|
+
}
|
|
35
|
+
// Check for CRC/checksum errors
|
|
36
|
+
if (message.includes('crc') || message.includes('checksum')) {
|
|
37
|
+
return ErrorType.CRC;
|
|
38
|
+
}
|
|
39
|
+
// Check for Modbus exceptions
|
|
40
|
+
if (/modbus\s+exception/i.test(message) ||
|
|
41
|
+
/exception\s+code\s+0x[0-9a-f]+/i.test(message) ||
|
|
42
|
+
/exception\s+\d+/.test(message)) {
|
|
43
|
+
return ErrorType.ModbusException;
|
|
44
|
+
}
|
|
45
|
+
return ErrorType.Unknown;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=error-classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-classifier.js","sourceRoot":"","sources":["../../../src/error-classifier.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAsBH,sCAwBC;AA5CD;;GAEG;AACH,IAAY,SASX;AATD,WAAY,SAAS;IACnB,0BAA0B;IAC1B,gCAAmB,CAAA;IACnB,wCAAwC;IACxC,wBAAW,CAAA;IACX,+CAA+C;IAC/C,iDAAoC,CAAA;IACpC,oCAAoC;IACpC,gCAAmB,CAAA;AACrB,CAAC,EATW,SAAS,yBAAT,SAAS,QASpB;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,KAAY;IACxC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;IAClD,MAAM,IAAI,GAAI,KAA+B,CAAC,IAAI,CAAA;IAElD,oBAAoB;IACpB,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzF,OAAO,SAAS,CAAC,OAAO,CAAA;IAC1B,CAAC;IAED,gCAAgC;IAChC,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5D,OAAO,SAAS,CAAC,GAAG,CAAA;IACtB,CAAC;IAED,8BAA8B;IAC9B,IACE,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC;QACnC,iCAAiC,CAAC,IAAI,CAAC,OAAO,CAAC;QAC/C,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,EAC/B,CAAC;QACD,OAAO,SAAS,CAAC,eAAe,CAAA;IAClC,CAAC;IAED,OAAO,SAAS,CAAC,OAAO,CAAA;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACxF,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,2BAA2B,GAC5B,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @ya-modbus/device-profiler - Device profiler for discovering Modbus register maps
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PROGRESS_UPDATE_INTERVAL_MS = exports.MIN_SLAVE_ID = exports.MIN_PORT = exports.MAX_SLAVE_ID = exports.MAX_PORT = exports.DEFAULT_BATCH_SIZE = exports.BYTES_PER_REGISTER = exports.scanRegisters = exports.RegisterType = exports.testRead = exports.formatSummary = exports.formatProgress = exports.ErrorType = exports.classifyError = void 0;
|
|
7
|
+
var error_classifier_js_1 = require("./error-classifier.js");
|
|
8
|
+
Object.defineProperty(exports, "classifyError", { enumerable: true, get: function () { return error_classifier_js_1.classifyError; } });
|
|
9
|
+
Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return error_classifier_js_1.ErrorType; } });
|
|
10
|
+
var console_formatter_js_1 = require("./console-formatter.js");
|
|
11
|
+
Object.defineProperty(exports, "formatProgress", { enumerable: true, get: function () { return console_formatter_js_1.formatProgress; } });
|
|
12
|
+
Object.defineProperty(exports, "formatSummary", { enumerable: true, get: function () { return console_formatter_js_1.formatSummary; } });
|
|
13
|
+
var read_tester_js_1 = require("./read-tester.js");
|
|
14
|
+
Object.defineProperty(exports, "testRead", { enumerable: true, get: function () { return read_tester_js_1.testRead; } });
|
|
15
|
+
Object.defineProperty(exports, "RegisterType", { enumerable: true, get: function () { return read_tester_js_1.RegisterType; } });
|
|
16
|
+
var register_scanner_js_1 = require("./register-scanner.js");
|
|
17
|
+
Object.defineProperty(exports, "scanRegisters", { enumerable: true, get: function () { return register_scanner_js_1.scanRegisters; } });
|
|
18
|
+
var constants_js_1 = require("./constants.js");
|
|
19
|
+
Object.defineProperty(exports, "BYTES_PER_REGISTER", { enumerable: true, get: function () { return constants_js_1.BYTES_PER_REGISTER; } });
|
|
20
|
+
Object.defineProperty(exports, "DEFAULT_BATCH_SIZE", { enumerable: true, get: function () { return constants_js_1.DEFAULT_BATCH_SIZE; } });
|
|
21
|
+
Object.defineProperty(exports, "MAX_PORT", { enumerable: true, get: function () { return constants_js_1.MAX_PORT; } });
|
|
22
|
+
Object.defineProperty(exports, "MAX_SLAVE_ID", { enumerable: true, get: function () { return constants_js_1.MAX_SLAVE_ID; } });
|
|
23
|
+
Object.defineProperty(exports, "MIN_PORT", { enumerable: true, get: function () { return constants_js_1.MIN_PORT; } });
|
|
24
|
+
Object.defineProperty(exports, "MIN_SLAVE_ID", { enumerable: true, get: function () { return constants_js_1.MIN_SLAVE_ID; } });
|
|
25
|
+
Object.defineProperty(exports, "PROGRESS_UPDATE_INTERVAL_MS", { enumerable: true, get: function () { return constants_js_1.PROGRESS_UPDATE_INTERVAL_MS; } });
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,6DAAgE;AAAvD,oHAAA,aAAa,OAAA;AAAE,gHAAA,SAAS,OAAA;AACjC,+DAAsE;AAA7D,sHAAA,cAAc,OAAA;AAAE,qHAAA,aAAa,OAAA;AACtC,mDAA8E;AAArE,0GAAA,QAAQ,OAAA;AAAE,8GAAA,YAAY,OAAA;AAC/B,6DAAwF;AAA/E,oHAAA,aAAa,OAAA;AACtB,+CAQuB;AAPrB,kHAAA,kBAAkB,OAAA;AAClB,kHAAA,kBAAkB,OAAA;AAClB,wGAAA,QAAQ,OAAA;AACR,4GAAA,YAAY,OAAA;AACZ,wGAAA,QAAQ,OAAA;AACR,4GAAA,YAAY,OAAA;AACZ,2HAAA,2BAA2B,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../../src/program.ts"],"names":[],"mappings":";AAEA;;GAEG;AAIH,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAA;AAsB3C,eAAO,MAAM,OAAO,SAAgB,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* CLI program for device profiler
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.program = void 0;
|
|
8
|
+
const transport_1 = require("@ya-modbus/transport");
|
|
9
|
+
const commander_1 = require("commander");
|
|
10
|
+
const cli_js_1 = require("./cli.js");
|
|
11
|
+
const constants_js_1 = require("./constants.js");
|
|
12
|
+
const read_tester_js_1 = require("./read-tester.js");
|
|
13
|
+
const parseNumber = (value) => parseInt(value, 10);
|
|
14
|
+
exports.program = new commander_1.Command();
|
|
15
|
+
exports.program
|
|
16
|
+
.name('ya-modbus-profile')
|
|
17
|
+
.description('Profile Modbus devices by scanning register ranges')
|
|
18
|
+
.version('0.1.0')
|
|
19
|
+
.requiredOption('--port <port>', 'Serial port (e.g., /dev/ttyUSB0) or TCP host:port')
|
|
20
|
+
.requiredOption('--slave-id <id>', 'Modbus slave ID (1-247)', parseNumber)
|
|
21
|
+
.option('--type <type>', 'Register type: holding or input', 'holding')
|
|
22
|
+
.option('--start <address>', 'Start register address', parseNumber, 0)
|
|
23
|
+
.option('--end <address>', 'End register address', parseNumber, 100)
|
|
24
|
+
.option('--batch <size>', 'Batch size for reads', parseNumber, 10)
|
|
25
|
+
.option('--baud <rate>', 'Baud rate for RTU', parseNumber, 9600)
|
|
26
|
+
.addOption(new commander_1.Option('--parity <parity>', 'Parity for RTU')
|
|
27
|
+
.choices(['none', 'even', 'odd'])
|
|
28
|
+
.default('none'))
|
|
29
|
+
.option('--data-bits <bits>', 'Data bits for RTU', parseNumber, 8)
|
|
30
|
+
.option('--stop-bits <bits>', 'Stop bits for RTU', parseNumber, 1)
|
|
31
|
+
.option('--timeout <ms>', 'Response timeout in milliseconds', parseNumber, 1000)
|
|
32
|
+
.action(async (options) => {
|
|
33
|
+
try {
|
|
34
|
+
const registerType = options.type === 'input' ? read_tester_js_1.RegisterType.Input : read_tester_js_1.RegisterType.Holding;
|
|
35
|
+
let transport;
|
|
36
|
+
if (options.port.includes(':')) {
|
|
37
|
+
const parts = options.port.split(':');
|
|
38
|
+
const host = parts[0];
|
|
39
|
+
const portStr = parts[1];
|
|
40
|
+
if (!host || !portStr) {
|
|
41
|
+
throw new Error('Invalid TCP address format. Expected host:port');
|
|
42
|
+
}
|
|
43
|
+
const port = parseInt(portStr, 10);
|
|
44
|
+
if (isNaN(port) || port < constants_js_1.MIN_PORT || port > constants_js_1.MAX_PORT) {
|
|
45
|
+
throw new Error(`Invalid port number: ${portStr}. Must be between ${constants_js_1.MIN_PORT} and ${constants_js_1.MAX_PORT}`);
|
|
46
|
+
}
|
|
47
|
+
transport = await (0, transport_1.createTransport)({
|
|
48
|
+
host,
|
|
49
|
+
port,
|
|
50
|
+
slaveId: options.slaveId,
|
|
51
|
+
timeout: options.timeout,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
transport = await (0, transport_1.createTransport)({
|
|
56
|
+
port: options.port,
|
|
57
|
+
baudRate: options.baud,
|
|
58
|
+
dataBits: options.dataBits,
|
|
59
|
+
parity: options.parity,
|
|
60
|
+
stopBits: options.stopBits,
|
|
61
|
+
slaveId: options.slaveId,
|
|
62
|
+
timeout: options.timeout,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
await (0, cli_js_1.runProfileScan)({
|
|
66
|
+
transport,
|
|
67
|
+
type: registerType,
|
|
68
|
+
startAddress: options.start,
|
|
69
|
+
endAddress: options.end,
|
|
70
|
+
batchSize: options.batch,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error('Error:', error instanceof Error ? error.message : String(error));
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=program.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program.js","sourceRoot":"","sources":["../../../src/program.ts"],"names":[],"mappings":";;AAEA;;GAEG;;;AAGH,oDAAsD;AACtD,yCAA2C;AAE3C,qCAAyC;AACzC,iDAAmD;AACnD,qDAA+C;AAgB/C,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAErD,QAAA,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAA;AAEpC,eAAO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AG;YACvB,SAAS,EAAE,OAAO,CAAC,KAAK;SACzB,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QAC/E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-tester.d.ts","sourceRoot":"","sources":["../../../src/read-tester.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,EAAiB,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEhE;;GAEG;AACH,oBAAY,YAAY;IACtB,+BAA+B;IAC/B,OAAO,YAAY;IACnB,6BAA6B;IAC7B,KAAK,UAAU;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAA;IAChB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAA;IACd,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sCAAsC;IACtC,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,CAC5B,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,CAAC,CA6BzB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Read testing utilities for Modbus registers
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RegisterType = void 0;
|
|
7
|
+
exports.testRead = testRead;
|
|
8
|
+
const error_classifier_js_1 = require("./error-classifier.js");
|
|
9
|
+
/**
|
|
10
|
+
* Modbus register type
|
|
11
|
+
*/
|
|
12
|
+
var RegisterType;
|
|
13
|
+
(function (RegisterType) {
|
|
14
|
+
/** Holding registers (FC03) */
|
|
15
|
+
RegisterType["Holding"] = "holding";
|
|
16
|
+
/** Input registers (FC04) */
|
|
17
|
+
RegisterType["Input"] = "input";
|
|
18
|
+
})(RegisterType || (exports.RegisterType = RegisterType = {}));
|
|
19
|
+
/**
|
|
20
|
+
* Test reading a register with timing measurement
|
|
21
|
+
*
|
|
22
|
+
* @param transport - Modbus transport
|
|
23
|
+
* @param type - Register type (holding or input)
|
|
24
|
+
* @param address - Starting register address
|
|
25
|
+
* @param count - Number of registers to read
|
|
26
|
+
* @returns Read test result with timing information
|
|
27
|
+
*/
|
|
28
|
+
async function testRead(transport, type, address, count) {
|
|
29
|
+
const startTime = performance.now();
|
|
30
|
+
try {
|
|
31
|
+
let data;
|
|
32
|
+
if (type === RegisterType.Holding) {
|
|
33
|
+
data = await transport.readHoldingRegisters(address, count);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
data = await transport.readInputRegisters(address, count);
|
|
37
|
+
}
|
|
38
|
+
const timing = performance.now() - startTime;
|
|
39
|
+
return {
|
|
40
|
+
success: true,
|
|
41
|
+
data,
|
|
42
|
+
timing,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
const timing = performance.now() - startTime;
|
|
47
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
timing,
|
|
51
|
+
error: error.message,
|
|
52
|
+
errorType: (0, error_classifier_js_1.classifyError)(error),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=read-tester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-tester.js","sourceRoot":"","sources":["../../../src/read-tester.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAyCH,4BAkCC;AAvED,+DAAgE;AAEhE;;GAEG;AACH,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,+BAA+B;IAC/B,mCAAmB,CAAA;IACnB,6BAA6B;IAC7B,+BAAe,CAAA;AACjB,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AAkBD;;;;;;;;GAQG;AACI,KAAK,UAAU,QAAQ,CAC5B,SAAoB,EACpB,IAAkB,EAClB,OAAe,EACf,KAAa;IAEb,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAA;IAEnC,IAAI,CAAC;QACH,IAAI,IAAY,CAAA;QAChB,IAAI,IAAI,KAAK,YAAY,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,GAAG,MAAM,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAC3D,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;QAE5C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,IAAI;YACJ,MAAM;SACP,CAAA;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;QAC5C,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;QAEjE,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM;YACN,KAAK,EAAE,KAAK,CAAC,OAAO;YACpB,SAAS,EAAE,IAAA,mCAAa,EAAC,KAAK,CAAC;SAChC,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-scanner.d.ts","sourceRoot":"","sources":["../../../src/register-scanner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAY,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEzD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,oBAAoB;IACpB,IAAI,EAAE,YAAY,CAAA;IAClB,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAA;IAChB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAA;IACd,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sCAAsC;IACtC,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,uBAAuB;IACvB,SAAS,EAAE,SAAS,CAAA;IACpB,4BAA4B;IAC5B,IAAI,EAAE,YAAY,CAAA;IAClB,gCAAgC;IAChC,YAAY,EAAE,MAAM,CAAA;IACpB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAA;IAClB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oCAAoC;IACpC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACrD,wCAAwC;IACxC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAA;CACxC;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA4EvE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Register scanner with batch reading and automatic fallback
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.scanRegisters = scanRegisters;
|
|
7
|
+
const constants_js_1 = require("./constants.js");
|
|
8
|
+
const read_tester_js_1 = require("./read-tester.js");
|
|
9
|
+
/**
|
|
10
|
+
* Scan a range of registers with batch reads and automatic fallback
|
|
11
|
+
*
|
|
12
|
+
* @param options - Scan configuration
|
|
13
|
+
*/
|
|
14
|
+
async function scanRegisters(options) {
|
|
15
|
+
const { transport, type, startAddress, endAddress, batchSize = constants_js_1.DEFAULT_BATCH_SIZE, onProgress, onResult, } = options;
|
|
16
|
+
const totalRegisters = endAddress - startAddress + 1;
|
|
17
|
+
let scannedCount = 0;
|
|
18
|
+
// Process registers in batches
|
|
19
|
+
for (let address = startAddress; address <= endAddress; address += batchSize) {
|
|
20
|
+
const count = Math.min(batchSize, endAddress - address + 1);
|
|
21
|
+
// Try batch read first
|
|
22
|
+
const batchResult = await (0, read_tester_js_1.testRead)(transport, type, address, count);
|
|
23
|
+
if (batchResult.success && batchResult.data) {
|
|
24
|
+
// Batch read succeeded, split results
|
|
25
|
+
for (let i = 0; i < count; i++) {
|
|
26
|
+
const regAddress = address + i;
|
|
27
|
+
const value = batchResult.data.subarray(i * constants_js_1.BYTES_PER_REGISTER, (i + 1) * constants_js_1.BYTES_PER_REGISTER);
|
|
28
|
+
const result = {
|
|
29
|
+
address: regAddress,
|
|
30
|
+
type,
|
|
31
|
+
success: true,
|
|
32
|
+
value,
|
|
33
|
+
timing: batchResult.timing / count,
|
|
34
|
+
};
|
|
35
|
+
if (onResult) {
|
|
36
|
+
onResult(result);
|
|
37
|
+
}
|
|
38
|
+
scannedCount++;
|
|
39
|
+
if (onProgress) {
|
|
40
|
+
onProgress(scannedCount, totalRegisters);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Batch read failed, fallback to individual reads
|
|
46
|
+
for (let i = 0; i < count; i++) {
|
|
47
|
+
const regAddress = address + i;
|
|
48
|
+
const individualResult = await (0, read_tester_js_1.testRead)(transport, type, regAddress, 1);
|
|
49
|
+
const result = {
|
|
50
|
+
address: regAddress,
|
|
51
|
+
type,
|
|
52
|
+
success: individualResult.success,
|
|
53
|
+
...(individualResult.data !== undefined && { value: individualResult.data }),
|
|
54
|
+
timing: individualResult.timing,
|
|
55
|
+
...(individualResult.error !== undefined && { error: individualResult.error }),
|
|
56
|
+
...(individualResult.errorType !== undefined && {
|
|
57
|
+
errorType: individualResult.errorType,
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
if (onResult) {
|
|
61
|
+
onResult(result);
|
|
62
|
+
}
|
|
63
|
+
scannedCount++;
|
|
64
|
+
if (onProgress) {
|
|
65
|
+
onProgress(scannedCount, totalRegisters);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=register-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-scanner.js","sourceRoot":"","sources":["../../../src/register-scanner.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAqDH,sCA4EC;AA7HD,iDAAuE;AAEvE,qDAAyD;AA0CzD;;;;GAIG;AACI,KAAK,UAAU,aAAa,CAAC,OAAoB;IACtD,MAAM,EACJ,SAAS,EACT,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,SAAS,GAAG,iCAAkB,EAC9B,UAAU,EACV,QAAQ,GACT,GAAG,OAAO,CAAA;IAEX,MAAM,cAAc,GAAG,UAAU,GAAG,YAAY,GAAG,CAAC,CAAA;IACpD,IAAI,YAAY,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