@ya-modbus/transport 0.12.2 → 0.13.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 +6 -0
- package/README.md +14 -1
- package/dist/cjs/src/manager.d.ts +4 -3
- package/dist/cjs/src/manager.d.ts.map +1 -1
- package/dist/cjs/src/manager.js +10 -5
- package/dist/cjs/src/manager.js.map +1 -1
- package/dist/cjs/src/request-context.d.ts +27 -0
- package/dist/cjs/src/request-context.d.ts.map +1 -0
- package/dist/cjs/src/request-context.js +81 -0
- package/dist/cjs/src/request-context.js.map +1 -0
- package/dist/cjs/src/rtu-transport.d.ts.map +1 -1
- package/dist/cjs/src/rtu-transport.js +2 -1
- package/dist/cjs/src/rtu-transport.js.map +1 -1
- package/dist/cjs/src/tcp-transport.d.ts.map +1 -1
- package/dist/cjs/src/tcp-transport.js +2 -1
- package/dist/cjs/src/tcp-transport.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/manager.d.ts +4 -3
- package/dist/esm/src/manager.d.ts.map +1 -1
- package/dist/esm/src/manager.js +10 -5
- package/dist/esm/src/manager.js.map +1 -1
- package/dist/esm/src/request-context.d.ts +27 -0
- package/dist/esm/src/request-context.d.ts.map +1 -0
- package/dist/esm/src/request-context.js +77 -0
- package/dist/esm/src/request-context.js.map +1 -0
- package/dist/esm/src/rtu-transport.d.ts.map +1 -1
- package/dist/esm/src/rtu-transport.js +2 -1
- package/dist/esm/src/rtu-transport.js.map +1 -1
- package/dist/esm/src/tcp-transport.d.ts.map +1 -1
- package/dist/esm/src/tcp-transport.js +2 -1
- package/dist/esm/src/tcp-transport.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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.13.0](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/transport@0.12.2...@ya-modbus/transport@0.13.0) (2026-10-15)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **transport:** name port, slave, function and registers in request errors ([#648](https://github.com/groupsky/ya-modbus/issues/648)) ([48f185c](https://github.com/groupsky/ya-modbus/commit/48f185c0ab2a149f8611055882a101713f0be707)), closes [#605](https://github.com/groupsky/ya-modbus/issues/605)
|
|
11
|
+
|
|
6
12
|
## [0.12.2](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/transport@0.12.1...@ya-modbus/transport@0.12.2) (2026-10-15)
|
|
7
13
|
|
|
8
14
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -118,6 +118,18 @@ try {
|
|
|
118
118
|
|
|
119
119
|
`normalizeModbusError(error)` applies the same conversion to any caught value.
|
|
120
120
|
|
|
121
|
+
### Errors of failed requests
|
|
122
|
+
|
|
123
|
+
Only `TransportManager.getTransport()`, `createRTUTransport()` and `createTCPTransport()` add the
|
|
124
|
+
details (not `SlaveTransport` or `createModbusTransport()` used directly) of the request to the message of a failed request, after all retries. The message ends with
|
|
125
|
+
the port or host, serial settings, slave ID, function code, start address and count, for example
|
|
126
|
+
`Timed out (/dev/ttyUSB0 9600 8E1, slave 1, FC03 read holding registers, address 16 (0x0010), count 2)`
|
|
127
|
+
or `Timed out (192.168.1.10:502, slave 1, FC04 read input registers, address 0 (0x0000), count 10)`.
|
|
128
|
+
The serial settings are baud rate, data bits, parity and stop bits. `name`, `code`, `errno`,
|
|
129
|
+
`modbusCode` and `cause` are those of the original error. The retry logger gets the errors without
|
|
130
|
+
details. A timeout can also mean wrong serial settings or a register that the device does not
|
|
131
|
+
have, because many devices do not answer then.
|
|
132
|
+
|
|
121
133
|
### Lost connections
|
|
122
134
|
|
|
123
135
|
When a USB serial adapter is unplugged or a TCP connection closes, `modbus-serial` emits a
|
|
@@ -128,7 +140,8 @@ so the process does not crash. The connection is then lost:
|
|
|
128
140
|
- Later requests reject at once, without using the port.
|
|
129
141
|
- The error has the name `ConnectionLostError` and a message like
|
|
130
142
|
`Connection to /dev/ttyUSB0 lost: port closed`, or
|
|
131
|
-
`Connection to /dev/ttyUSB0 lost: EIO: i/o error, write` when a write failed
|
|
143
|
+
`Connection to /dev/ttyUSB0 lost: EIO: i/o error, write` when a write failed (followed by the
|
|
144
|
+
details of the request, as above). The underlying
|
|
132
145
|
error is in `cause`. `code` and `errno` are set only when the underlying error is a Node.js
|
|
133
146
|
system error, for example `ECONNREFUSED` when a TCP connection cannot be opened again.
|
|
134
147
|
|
|
@@ -30,7 +30,7 @@ export interface TransportStats {
|
|
|
30
30
|
* - Pools modbus-serial clients by physical connection (excluding slave ID)
|
|
31
31
|
* - RTU clients are pooled by bus configuration (port, baud rate, parity, etc.)
|
|
32
32
|
* - TCP clients are pooled by host and port
|
|
33
|
-
* - Returns SlaveTransport
|
|
33
|
+
* - Returns Transport objects (SlaveTransport wrapped with request details in errors) that set the slave ID before each operation
|
|
34
34
|
* - Multiple devices on the same connection share a single client and mutex
|
|
35
35
|
* - All operations are serialized using async-mutex to prevent race conditions
|
|
36
36
|
* - A lost connection (USB adapter unplugged, TCP connection closed) drops the client.
|
|
@@ -63,11 +63,12 @@ export declare class TransportManager {
|
|
|
63
63
|
constructor(options?: TransportManagerOptions);
|
|
64
64
|
/**
|
|
65
65
|
* Get or create a transport for the given configuration.
|
|
66
|
-
* Returns a new
|
|
66
|
+
* Returns a new Transport bound to the slave ID in the config.
|
|
67
67
|
* Multiple devices on the same physical connection share the same client and mutex.
|
|
68
68
|
*
|
|
69
69
|
* @param config - RTU or TCP transport configuration
|
|
70
|
-
* @returns
|
|
70
|
+
* @returns Transport for the specific slave device. It wraps a SlaveTransport, and the
|
|
71
|
+
* message of a failed request ends with the port, slave, function and registers.
|
|
71
72
|
* @throws When the port cannot be opened, unless the `startLost` option is set
|
|
72
73
|
*/
|
|
73
74
|
getTransport(config: TransportConfig): Promise<Transport>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAMxD,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAMxD,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAe7E;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,gBAAgB;IAOf,OAAO,CAAC,QAAQ,CAAC,OAAO;IANpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IAEjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8C;IAEtE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;gBAEtB,OAAO,GAAE,uBAA4B;IAElE;;;;;;;;;OASG;IACG,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IA6B/D;;;;;;;;;;;OAWG;IACG,gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAc3D;;;;;;OAMG;YACW,cAAc;IA2B5B;;;;;;OAMG;IACH,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,GAAG,SAAS;IAIpE;;;;OAIG;IACH,QAAQ,IAAI,cAAc;IAS1B;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B;;;;;OAKG;YACW,eAAe;IAQ7B;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;IAShC;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;;;OAMG;YACW,eAAe;IAe7B;;;;;;OAMG;YACW,eAAe;IAU7B;;;;;OAKG;IACH,OAAO,CAAC,WAAW;CAGpB"}
|
package/dist/cjs/src/manager.js
CHANGED
|
@@ -7,6 +7,7 @@ const modbus_serial_1 = tslib_1.__importDefault(require("modbus-serial"));
|
|
|
7
7
|
const client_config_js_1 = require("./client-config.js");
|
|
8
8
|
const connection_js_1 = require("./connection.js");
|
|
9
9
|
const normalize_error_js_1 = require("./normalize-error.js");
|
|
10
|
+
const request_context_js_1 = require("./request-context.js");
|
|
10
11
|
const slave_transport_js_1 = require("./slave-transport.js");
|
|
11
12
|
/**
|
|
12
13
|
* TransportManager pools modbus-serial clients and provides slave-specific transports.
|
|
@@ -15,7 +16,7 @@ const slave_transport_js_1 = require("./slave-transport.js");
|
|
|
15
16
|
* - Pools modbus-serial clients by physical connection (excluding slave ID)
|
|
16
17
|
* - RTU clients are pooled by bus configuration (port, baud rate, parity, etc.)
|
|
17
18
|
* - TCP clients are pooled by host and port
|
|
18
|
-
* - Returns SlaveTransport
|
|
19
|
+
* - Returns Transport objects (SlaveTransport wrapped with request details in errors) that set the slave ID before each operation
|
|
19
20
|
* - Multiple devices on the same connection share a single client and mutex
|
|
20
21
|
* - All operations are serialized using async-mutex to prevent race conditions
|
|
21
22
|
* - A lost connection (USB adapter unplugged, TCP connection closed) drops the client.
|
|
@@ -51,11 +52,12 @@ class TransportManager {
|
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Get or create a transport for the given configuration.
|
|
54
|
-
* Returns a new
|
|
55
|
+
* Returns a new Transport bound to the slave ID in the config.
|
|
55
56
|
* Multiple devices on the same physical connection share the same client and mutex.
|
|
56
57
|
*
|
|
57
58
|
* @param config - RTU or TCP transport configuration
|
|
58
|
-
* @returns
|
|
59
|
+
* @returns Transport for the specific slave device. It wraps a SlaveTransport, and the
|
|
60
|
+
* message of a failed request ends with the port, slave, function and registers.
|
|
59
61
|
* @throws When the port cannot be opened, unless the `startLost` option is set
|
|
60
62
|
*/
|
|
61
63
|
async getTransport(config) {
|
|
@@ -72,8 +74,11 @@ class TransportManager {
|
|
|
72
74
|
}
|
|
73
75
|
// Return a new SlaveTransport for this specific slave
|
|
74
76
|
const transport = new slave_transport_js_1.SlaveTransport(config.slaveId, entry.connection, entry.mutex, config.maxRetries ?? 3, config.logger);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
const target = this.getTarget(config);
|
|
78
|
+
const where = this.isRTUConfig(config) ? `${target} ${(0, request_context_js_1.formatSerialSettings)(config)}` : target;
|
|
79
|
+
const described = (0, request_context_js_1.withRequestContext)(transport, `${where}, slave ${config.slaveId}`);
|
|
80
|
+
entry.transports.add(described);
|
|
81
|
+
return described;
|
|
77
82
|
}
|
|
78
83
|
/**
|
|
79
84
|
* Release the transport of a device that does not use it any more, for example a device
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/manager.ts"],"names":[],"mappings":";;;;AACA,6CAAmC;AACnC,0EAAqC;AAErC,yDAAmE;AACnE,mDAAkD;AAElD,6DAA6E;AAC7E,6DAAqD;AAqCrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,gBAAgB;IAO3B,YAA6B,UAAmC,EAAE;QAArC,YAAO,GAAP,OAAO,CAA8B;QANjD,gBAAW,GAAG,IAAI,GAAG,EAA2B,CA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;OAMG;IACK,KAAK,CAAC,eAAe,CAAC,MAAiB;QAC7C,MAAM,MAAM,GAAG,IAAI,uBAAS,EAAE,CAAA;QAE9B,MAAM,IAAA,6BAAU,EAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QAEzE,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,IAAI,qCAAkB,CAAC,CAAA;QAEvD,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;;OAKG;IACK,WAAW,CAAC,MAAuB;QACzC,OAAO,MAAM,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,CAAA;IACnF,CAAC;CACF;AAlPD,4CAkPC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context for failed requests: which port, slave, function and registers
|
|
3
|
+
*/
|
|
4
|
+
import type { Transport } from '@ya-modbus/driver-types';
|
|
5
|
+
/**
|
|
6
|
+
* Serial settings in the usual short form, from the settings that are present
|
|
7
|
+
*
|
|
8
|
+
* @example formatSerialSettings({ baudRate: 9600, dataBits: 8, parity: 'even', stopBits: 1 }) // '9600 8E1'
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatSerialSettings(settings: {
|
|
11
|
+
baudRate?: number | undefined;
|
|
12
|
+
dataBits?: number | undefined;
|
|
13
|
+
parity?: string | undefined;
|
|
14
|
+
stopBits?: number | undefined;
|
|
15
|
+
}): string;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap a Transport so that a failed request says where it went
|
|
18
|
+
*
|
|
19
|
+
* The error message gets the label and the request appended, for example
|
|
20
|
+
* `Timed out (/dev/ttyUSB0 9600 8E1, slave 1, FC03 read holding registers, address 16 (0x0010), count 2)`.
|
|
21
|
+
* Retries of the wrapped transport are not changed.
|
|
22
|
+
*
|
|
23
|
+
* @param transport - Transport to wrap
|
|
24
|
+
* @param label - Port or host, serial settings and slave, shown in the message
|
|
25
|
+
*/
|
|
26
|
+
export declare function withRequestContext(transport: Transport, label: string): Transport;
|
|
27
|
+
//# sourceMappingURL=request-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../../../src/request-context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AA2BxD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE;IAC7C,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,GAAG,MAAM,CAIT;AAsBD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAoBjF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Context for failed requests: which port, slave, function and registers
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatSerialSettings = formatSerialSettings;
|
|
7
|
+
exports.withRequestContext = withRequestContext;
|
|
8
|
+
const normalize_error_js_1 = require("./normalize-error.js");
|
|
9
|
+
/** How each request of a Transport is named in error messages, and how many items it covers */
|
|
10
|
+
const REQUESTS = {
|
|
11
|
+
readCoils: { code: 1, name: 'read coils', count: (n) => n },
|
|
12
|
+
readDiscreteInputs: { code: 2, name: 'read discrete inputs', count: (n) => n },
|
|
13
|
+
readHoldingRegisters: { code: 3, name: 'read holding registers', count: (n) => n },
|
|
14
|
+
readInputRegisters: { code: 4, name: 'read input registers', count: (n) => n },
|
|
15
|
+
writeSingleCoil: { code: 5, name: 'write single coil', count: () => 1 },
|
|
16
|
+
writeSingleRegister: { code: 6, name: 'write single register', count: () => 1 },
|
|
17
|
+
writeMultipleCoils: {
|
|
18
|
+
code: 15,
|
|
19
|
+
name: 'write multiple coils',
|
|
20
|
+
count: (values) => values.length * 8,
|
|
21
|
+
},
|
|
22
|
+
writeMultipleRegisters: {
|
|
23
|
+
code: 16,
|
|
24
|
+
name: 'write multiple registers',
|
|
25
|
+
count: (values) => values.length / 2,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Serial settings in the usual short form, from the settings that are present
|
|
30
|
+
*
|
|
31
|
+
* @example formatSerialSettings({ baudRate: 9600, dataBits: 8, parity: 'even', stopBits: 1 }) // '9600 8E1'
|
|
32
|
+
*/
|
|
33
|
+
function formatSerialSettings(settings) {
|
|
34
|
+
const { baudRate, dataBits, parity, stopBits } = settings;
|
|
35
|
+
const frame = `${dataBits ?? ''}${parity?.charAt(0).toUpperCase() ?? ''}${stopBits ?? ''}`;
|
|
36
|
+
return [baudRate, frame].filter((part) => part !== undefined && part !== '').join(' ');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Copy of an error with a new message
|
|
40
|
+
*
|
|
41
|
+
* Name, code, errno, modbusCode and cause stay, and the stack starts with the new message.
|
|
42
|
+
* The error is copied because a lost connection rejects all requests with the same
|
|
43
|
+
* object, and the details of one request must not pile up on it.
|
|
44
|
+
*/
|
|
45
|
+
function withMessage(error, message) {
|
|
46
|
+
const copy = Object.assign(new Error(message, error.cause === undefined ? undefined : { cause: error.cause }), error);
|
|
47
|
+
copy.message = message;
|
|
48
|
+
copy.name = error.name;
|
|
49
|
+
if (error.stack !== undefined && error.message !== '') {
|
|
50
|
+
copy.stack = error.stack.replace(error.message, () => message);
|
|
51
|
+
}
|
|
52
|
+
return copy;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Wrap a Transport so that a failed request says where it went
|
|
56
|
+
*
|
|
57
|
+
* The error message gets the label and the request appended, for example
|
|
58
|
+
* `Timed out (/dev/ttyUSB0 9600 8E1, slave 1, FC03 read holding registers, address 16 (0x0010), count 2)`.
|
|
59
|
+
* Retries of the wrapped transport are not changed.
|
|
60
|
+
*
|
|
61
|
+
* @param transport - Transport to wrap
|
|
62
|
+
* @param label - Port or host, serial settings and slave, shown in the message
|
|
63
|
+
*/
|
|
64
|
+
function withRequestContext(transport, label) {
|
|
65
|
+
const wrapped = { close: () => transport.close() };
|
|
66
|
+
for (const [method, request] of Object.entries(REQUESTS)) {
|
|
67
|
+
wrapped[method] = async (address, value) => {
|
|
68
|
+
try {
|
|
69
|
+
return await transport[method](address, value);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
const normalized = (0, normalize_error_js_1.normalizeModbusError)(error);
|
|
73
|
+
const hex = `0x${address.toString(16).toUpperCase().padStart(4, '0')}`;
|
|
74
|
+
const code = String(request.code).padStart(2, '0');
|
|
75
|
+
throw withMessage(normalized, `${normalized.message} (${label}, FC${code} ${request.name}, address ${address} (${hex}), count ${request.count(value)})`);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return wrapped;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=request-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.js","sourceRoot":"","sources":["../../../src/request-context.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAkCH,oDASC;AAgCD,gDAoBC;AA3FD,6DAA6E;AAE7E,+FAA+F;AAC/F,MAAM,QAAQ,GAGV;IACF,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAW,EAAE;IACrE,kBAAkB,EAAE,EAAE,IAAI,EAAE,CAAC,EAA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C,CAAA;YACnB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,UAAU,GAAG,IAAA,yCAAoB,EAAC,KAAK,CAAC,CAAA;gBAC9C,MAAM,GAAG,GAAG,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAA;gBACtE,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;gBAClD,MAAM,WAAW,CACf,UAAU,EACV,GAAG,UAAU,CAAC,OAAO,KAAK,KAAK,OAAO,IAAI,IAAI,OAAO,CAAC,IAAI,aAAa,OAAO,KAAK,GAAG,YAAY,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAC1H,CAAA;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC;IACD,OAAO,OAA+B,CAAA;AACxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rtu-transport.d.ts","sourceRoot":"","sources":["../../../src/rtu-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"rtu-transport.d.ts","sourceRoot":"","sources":["../../../src/rtu-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAO9F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,gBAAgB;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa;IACb,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC;AAED;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAqB9E"}
|
|
@@ -6,6 +6,7 @@ const modbus_serial_1 = tslib_1.__importDefault(require("modbus-serial"));
|
|
|
6
6
|
const client_config_js_1 = require("./client-config.js");
|
|
7
7
|
const connection_js_1 = require("./connection.js");
|
|
8
8
|
const create_modbus_transport_js_1 = require("./create-modbus-transport.js");
|
|
9
|
+
const request_context_js_1 = require("./request-context.js");
|
|
9
10
|
/**
|
|
10
11
|
* Create an RTU transport
|
|
11
12
|
*
|
|
@@ -30,6 +31,6 @@ async function createRTUTransport(config) {
|
|
|
30
31
|
return client;
|
|
31
32
|
};
|
|
32
33
|
const connection = new connection_js_1.ModbusConnection(await open(), config.port, open);
|
|
33
|
-
return (0, create_modbus_transport_js_1.createModbusTransport)(connection, config.maxRetries, config.logger);
|
|
34
|
+
return (0, request_context_js_1.withRequestContext)((0, create_modbus_transport_js_1.createModbusTransport)(connection, config.maxRetries, config.logger), `${config.port} ${(0, request_context_js_1.formatSerialSettings)(config)}, slave ${config.slaveId}`);
|
|
34
35
|
}
|
|
35
36
|
//# sourceMappingURL=rtu-transport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rtu-transport.js","sourceRoot":"","sources":["../../../src/rtu-transport.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"rtu-transport.js","sourceRoot":"","sources":["../../../src/rtu-transport.ts"],"names":[],"mappings":";;AA2CA,gDAqBC;;AA/DD,0EAAqC;AAErC,yDAAoD;AACpD,mDAAkD;AAClD,6EAAoE;AACpE,6DAA+E;AA2B/E;;;;;;;;;GASG;AACI,KAAK,UAAU,kBAAkB,CAAC,MAAiB;IACxD,MAAM,IAAI,GAAG,KAAK,IAAwB,EAAE;QAC1C,MAAM,MAAM,GAAG,IAAI,uBAAS,EAAE,CAAA;QAE9B,yBAAyB;QACzB,MAAM,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE;YAC3C,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAA;QAEF,IAAA,kCAAe,EAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QACvD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAED,MAAM,UAAU,GAAG,IAAI,gCAAgB,CAAC,MAAM,IAAI,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IACxE,OAAO,IAAA,uCAAkB,EACvB,IAAA,kDAAqB,EAAC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EACnE,GAAG,MAAM,CAAC,IAAI,IAAI,IAAA,yCAAoB,EAAC,MAAM,CAAC,WAAW,MAAM,CAAC,OAAO,EAAE,CAC1E,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-transport.d.ts","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"tcp-transport.d.ts","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAOxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,yFAAyF;IACzF,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAiB9E"}
|
|
@@ -6,6 +6,7 @@ const modbus_serial_1 = tslib_1.__importDefault(require("modbus-serial"));
|
|
|
6
6
|
const client_config_js_1 = require("./client-config.js");
|
|
7
7
|
const connection_js_1 = require("./connection.js");
|
|
8
8
|
const create_modbus_transport_js_1 = require("./create-modbus-transport.js");
|
|
9
|
+
const request_context_js_1 = require("./request-context.js");
|
|
9
10
|
/**
|
|
10
11
|
* Create a TCP transport
|
|
11
12
|
*
|
|
@@ -25,6 +26,6 @@ async function createTCPTransport(config) {
|
|
|
25
26
|
return client;
|
|
26
27
|
};
|
|
27
28
|
const connection = new connection_js_1.ModbusConnection(await open(), `${config.host}:${port}`, open);
|
|
28
|
-
return (0, create_modbus_transport_js_1.createModbusTransport)(connection, config.maxRetries, config.logger);
|
|
29
|
+
return (0, request_context_js_1.withRequestContext)((0, create_modbus_transport_js_1.createModbusTransport)(connection, config.maxRetries, config.logger), `${config.host}:${port}, slave ${config.slaveId}`);
|
|
29
30
|
}
|
|
30
31
|
//# sourceMappingURL=tcp-transport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-transport.js","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"tcp-transport.js","sourceRoot":"","sources":["../../../src/tcp-transport.ts"],"names":[],"mappings":";;AAoCA,gDAiBC;;AApDD,0EAAqC;AAErC,yDAAgE;AAChE,mDAAkD;AAClD,6EAAoE;AACpE,6DAAyD;AAqBzD;;;;;;;;GAQG;AACI,KAAK,UAAU,kBAAkB,CAAC,MAAiB;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,GAAG,CAAA;IAC/B,MAAM,IAAI,GAAG,KAAK,IAAwB,EAAE;QAC1C,MAAM,MAAM,GAAG,IAAI,uBAAS,EAAE,CAAA;QAE9B,wBAAwB;QACxB,MAAM,IAAA,6BAAU,EAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QAE3D,IAAA,kCAAe,EAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QACvD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAED,MAAM,UAAU,GAAG,IAAI,gCAAgB,CAAC,MAAM,IAAI,EAAE,EAAE,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAA;IACrF,OAAO,IAAA,uCAAkB,EACvB,IAAA,kDAAqB,EAAC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EACnE,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,WAAW,MAAM,CAAC,OAAO,EAAE,CAClD,CAAA;AACH,CAAC"}
|