@ya-modbus/transport 0.8.1 → 0.9.1
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 +14 -0
- package/dist/cjs/src/factory.d.ts +2 -2
- package/dist/cjs/src/factory.js +12 -12
- package/dist/cjs/src/factory.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/factory.d.ts +2 -2
- package/dist/esm/src/factory.js +12 -12
- package/dist/esm/src/factory.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/esm/src/factory.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { createRTUTransport } from './rtu-transport.js';
|
|
2
2
|
import { createTCPTransport } from './tcp-transport.js';
|
|
3
3
|
/**
|
|
4
|
-
* Type guard to check if config is
|
|
4
|
+
* Type guard to check if config is TCP
|
|
5
5
|
*/
|
|
6
|
-
function
|
|
7
|
-
return '
|
|
6
|
+
function isTCPConfig(config) {
|
|
7
|
+
return 'host' in config;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Create a transport instance based on configuration
|
|
11
11
|
*
|
|
12
12
|
* Detects whether to create RTU or TCP transport based on the config:
|
|
13
|
-
* - If `
|
|
14
|
-
* -
|
|
13
|
+
* - If `host` is provided → TCP transport (`port` is the optional TCP port number)
|
|
14
|
+
* - Otherwise, if `port` is provided → RTU transport (`port` is the serial path)
|
|
15
15
|
*
|
|
16
16
|
* @param config - Transport configuration (RTU or TCP)
|
|
17
17
|
* @returns Transport implementation
|
|
18
18
|
* @throws Error if config is invalid
|
|
19
19
|
*/
|
|
20
20
|
export async function createTransport(config) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
if (isTCPConfig(config)) {
|
|
22
|
+
// A string `port` is a serial path, which cannot be combined with a TCP host
|
|
23
|
+
if (typeof config.port === 'string') {
|
|
24
|
+
throw new Error('Cannot specify both port (RTU) and host (TCP)');
|
|
25
|
+
}
|
|
26
|
+
return createTCPTransport(config);
|
|
24
27
|
}
|
|
25
|
-
if (
|
|
28
|
+
if ('port' in config) {
|
|
26
29
|
return createRTUTransport(config);
|
|
27
30
|
}
|
|
28
|
-
if ('host' in config) {
|
|
29
|
-
return createTCPTransport(config);
|
|
30
|
-
}
|
|
31
31
|
throw new Error('Either port (for RTU) or host (for TCP) must be specified');
|
|
32
32
|
}
|
|
33
33
|
//# sourceMappingURL=factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AAWvE;;GAEG;AACH,SAAS,WAAW,CAAC,MAAuB;IAC1C,OAAO,MAAM,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AAWvE;;GAEG;AACH,SAAS,WAAW,CAAC,MAAuB;IAC1C,OAAO,MAAM,IAAI,MAAM,CAAA;AACzB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAuB;IAC3D,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;QACxB,6EAA6E;QAC7E,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAClE,CAAC;QAED,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QACrB,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;AAC9E,CAAC"}
|