@ya-modbus/transport 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.
@@ -0,0 +1,33 @@
1
+ import type { BaudRate, DataBits, Parity, StopBits, Transport } from '@ya-modbus/driver-types';
2
+ import type { RetryLogger } from './retry.js';
3
+ /**
4
+ * RTU transport configuration
5
+ */
6
+ export interface RTUConfig {
7
+ /** Serial port path (e.g., /dev/ttyUSB0, COM1) */
8
+ port: string;
9
+ /** Baud rate */
10
+ baudRate: BaudRate;
11
+ /** Data bits */
12
+ dataBits: DataBits;
13
+ /** Parity */
14
+ parity: Parity;
15
+ /** Stop bits */
16
+ stopBits: StopBits;
17
+ /** Modbus slave ID (1-247) */
18
+ slaveId: number;
19
+ /** Response timeout in milliseconds (default: 1000) */
20
+ timeout?: number | undefined;
21
+ /** Maximum retry attempts (default: 3, use 1 to disable retries) */
22
+ maxRetries?: number | undefined;
23
+ /** Optional callback to log retry attempts for debugging */
24
+ logger?: RetryLogger | undefined;
25
+ }
26
+ /**
27
+ * Create an RTU transport
28
+ *
29
+ * @param config - RTU configuration
30
+ * @returns Transport implementation for RTU
31
+ */
32
+ export declare function createRTUTransport(config: RTUConfig): Promise<Transport>;
33
+ //# sourceMappingURL=rtu-transport.d.ts.map
@@ -0,0 +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;AAI9F,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;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAkB9E"}
@@ -0,0 +1,24 @@
1
+ import ModbusRTU from 'modbus-serial';
2
+ import { createModbusTransport } from './create-modbus-transport.js';
3
+ /**
4
+ * Create an RTU transport
5
+ *
6
+ * @param config - RTU configuration
7
+ * @returns Transport implementation for RTU
8
+ */
9
+ export async function createRTUTransport(config) {
10
+ const client = new ModbusRTU();
11
+ // Connect to serial port
12
+ await client.connectRTUBuffered(config.port, {
13
+ baudRate: config.baudRate,
14
+ dataBits: config.dataBits,
15
+ parity: config.parity,
16
+ stopBits: config.stopBits,
17
+ });
18
+ // Set slave ID
19
+ client.setID(config.slaveId);
20
+ // Set timeout
21
+ client.setTimeout(config.timeout ?? 1000);
22
+ return createModbusTransport(client, config.maxRetries, config.logger);
23
+ }
24
+ //# sourceMappingURL=rtu-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtu-transport.js","sourceRoot":"","sources":["../src/rtu-transport.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AA2BpE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAiB;IACxD,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAA;IAE9B,yBAAyB;IACzB,MAAM,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE;QAC3C,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC,CAAA;IAEF,eAAe;IACf,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAE5B,cAAc;IACd,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,CAAA;IAEzC,OAAO,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;AACxE,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Transport } from '@ya-modbus/driver-types';
2
+ import type { RetryLogger } from './retry.js';
3
+ /**
4
+ * TCP transport configuration
5
+ */
6
+ export interface TCPConfig {
7
+ /** TCP host (IP address or hostname) */
8
+ host: string;
9
+ /** TCP port (default: 502) */
10
+ port?: number | undefined;
11
+ /** Modbus slave ID (1-247) */
12
+ slaveId: number;
13
+ /** Response timeout in milliseconds (default: 1000) */
14
+ timeout?: number | undefined;
15
+ /** Maximum retry attempts (default: 3, use 1 to disable retries) */
16
+ maxRetries?: number | undefined;
17
+ /** Optional callback to log retry attempts for debugging */
18
+ logger?: RetryLogger | undefined;
19
+ }
20
+ /**
21
+ * Create a TCP transport
22
+ *
23
+ * @param config - TCP configuration
24
+ * @returns Transport implementation for TCP
25
+ */
26
+ export declare function createTCPTransport(config: TCPConfig): Promise<Transport>;
27
+ //# sourceMappingURL=tcp-transport.d.ts.map
@@ -0,0 +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;AAIxD,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,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;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAa9E"}
@@ -0,0 +1,19 @@
1
+ import ModbusRTU from 'modbus-serial';
2
+ import { createModbusTransport } from './create-modbus-transport.js';
3
+ /**
4
+ * Create a TCP transport
5
+ *
6
+ * @param config - TCP configuration
7
+ * @returns Transport implementation for TCP
8
+ */
9
+ export async function createTCPTransport(config) {
10
+ const client = new ModbusRTU();
11
+ // Connect to TCP server
12
+ await client.connectTCP(config.host, { port: config.port ?? 502 });
13
+ // Set slave ID
14
+ client.setID(config.slaveId);
15
+ // Set timeout
16
+ client.setTimeout(config.timeout ?? 1000);
17
+ return createModbusTransport(client, config.maxRetries, config.logger);
18
+ }
19
+ //# sourceMappingURL=tcp-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tcp-transport.js","sourceRoot":"","sources":["../src/tcp-transport.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAqBpE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAiB;IACxD,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAA;IAE9B,wBAAwB;IACxB,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC,CAAA;IAElE,eAAe;IACf,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAE5B,cAAc;IACd,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,CAAA;IAEzC,OAAO,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;AACxE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@ya-modbus/transport",
3
+ "version": "0.4.1-refactor-scope-driver-packages.0",
4
+ "description": "Modbus transport implementations for ya-modbus",
5
+ "keywords": [
6
+ "modbus",
7
+ "transport",
8
+ "rtu",
9
+ "tcp",
10
+ "serial",
11
+ "ya-modbus"
12
+ ],
13
+ "author": "Geno Roupsky <geno@roupsky.name>",
14
+ "license": "GPL-3.0-or-later",
15
+ "type": "module",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/groupsky/ya-modbus.git",
26
+ "directory": "packages/transport"
27
+ },
28
+ "homepage": "https://github.com/groupsky/ya-modbus/tree/main/packages/transport#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/groupsky/ya-modbus/issues"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc --build",
37
+ "clean": "rm -rf dist",
38
+ "test": "jest",
39
+ "lint": "eslint ."
40
+ },
41
+ "dependencies": {
42
+ "@ya-modbus/driver-types": "^0.4.1-refactor-scope-driver-packages.0",
43
+ "async-mutex": "^0.5.0",
44
+ "modbus-serial": "^8.0.18"
45
+ },
46
+ "gitHead": "b55d909d67dfff46fb79951e68a2d47ac3fab267"
47
+ }