modbus-webserial 0.9.0 → 0.9.2

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.
Files changed (3) hide show
  1. package/LICENSE +19 -1
  2. package/README.md +105 -15
  3. package/package.json +2 -2
package/LICENSE CHANGED
@@ -1,3 +1,21 @@
1
1
  MIT License
2
2
 
3
- todo
3
+ Copyright (c) 2025 Antti Kotajärvi <antti.kotajarvi@hotmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,15 +1,105 @@
1
- # modbus-webserial v0.9.0
2
-
3
- #### Alpha
4
- - Basic structure and layout
5
- #### -> Beta
6
- - Full modbus RTU coverage
7
- #### -> v0.9.0
8
- - Full passing tests
9
- - Smoke test passed
10
- - Full README.md
11
- - Build scripts
12
- #### -> v1.0.0
13
- - Couple of weeks of full deployment
14
- - Fixed bugs
15
- - Reviewed code
1
+ # modbus-webserial
2
+
3
+ Tiny zero-dependency library for communicating with a Modbus-RTU serial device from the browser via WebSerial.
4
+
5
+ ![npm](https://img.shields.io/npm/v/modbus-webserial)
6
+ ![size](https://img.shields.io/bundlephobia/minzip/modbus-webserial)
7
+ ![dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
8
+ ![CI](https://img.shields.io/github/actions/workflow/status/anttikotajarvi/modbus-webserial/ci.yaml?branch=main)
9
+ [![License](https://img.shields.io/npm/l/modbus-webserial)](./LICENSE)
10
+ ![types](https://img.shields.io/npm/types/modbus-webserial)
11
+ ![esm](https://img.shields.io/badge/esm-%F0%9F%9A%80-green)
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install modbus-webserial
17
+ ```
18
+
19
+ ## Usage
20
+ **Connect → read/write in browser**
21
+ ```javascript
22
+ import { ModbusRTU } from 'modbus-webserial';
23
+
24
+ // Prompt the WebSerial dialog and open port
25
+ const client = await ModbusRTU.openWebSerial({ baudRate: 9600 });
26
+ client.setID(1);
27
+
28
+ // Read holding registers 0x00 and 0x01
29
+ const { data } = await client.readHoldingRegisters(0, 2);
30
+ console.log('HR0=', data[0], 'HR1=', data[1]);
31
+
32
+ // Write values to holding registers 0x00 and 0x01
33
+ await client.writeRegisters(0, [0x0A, 0x0B]);
34
+ ```
35
+ **Can also be used *without* WebSerial for building modbus frames in any enviorement**
36
+ ```javascript
37
+ import {
38
+ buildReadHoldingRegisters,
39
+ buildWriteRegisters
40
+ } from 'modbus-webserial';
41
+
42
+ // Build a “Read Holding Registers” frame (ID=1, addr=0, qty=2)
43
+ const rawRead = buildReadHoldingRegisters(1, 0x00, 2);
44
+ console.log(rawRead);
45
+ // → Uint8Array [0x01, 0x03, 0x00, 0x00, 0x00, 0x02, CRC_LO, CRC_HI]
46
+
47
+ // Build a “Write Multiple Registers” frame (ID=1, addr=0, values=[10,11])
48
+ const rawWrite = buildWriteRegisters(1, 0x00, [0x0A, 0x0B]);
49
+ console.log(rawWrite);
50
+ // → Uint8Array [0x01, 0x10, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00,0x0A, 0x00,0x0B, CRC_LO, CRC_HI]
51
+ ```
52
+ > [!TIP]
53
+ > Check `src/index.ts` (or `dist/index.js`) for all exports
54
+ ## Supported Functions
55
+
56
+ ### Modbus Data Functions
57
+
58
+ The following Modbus-RTU function calls are implemented:
59
+
60
+ | Function | Description |
61
+ | --------------------------------- | ---------------------------------------- |
62
+ | `readCoils(addr, qty)` | FC 01 – Read coil status |
63
+ | `readDiscreteInputs(addr, qty)` | FC 02 – Read discrete input status |
64
+ | `readHoldingRegisters(addr, qty)` | FC 03 – Read holding registers |
65
+ | `readInputRegisters(addr, qty)` | FC 04 – Read input registers |
66
+ | `writeCoil(addr, state)` | FC 05 – Write single coil |
67
+ | `writeRegister(addr, value)` | FC 06 – Write single holding register |
68
+ | `writeCoils(addr, states)` | FC 15 – Write multiple coils |
69
+ | `writeRegisters(addr, values)` | FC 16 – Write multiple holding registers |
70
+
71
+ ### Auxiliary Client Methods
72
+
73
+ Utility and configuration methods exposed on `ModbusRTU`:
74
+
75
+ | Method | Purpose |
76
+ | ------------------------ | ----------------------------------- |
77
+ | `openWebSerial(options)` | Open a serial port via WebSerial |
78
+ | `close()` | Close the current serial connection |
79
+ | `setID(id)` | Set the Modbus slave ID |
80
+ | `getID()` | Get the current slave ID |
81
+ | `setTimeout(ms)` | Set transaction timeout (ms) |
82
+ | `getTimeout()` | Get current timeout (ms) |
83
+
84
+ ## Examples
85
+
86
+ The following demos are fully self‑contained HTML files, served via GitHub Pages:
87
+
88
+ * [Basic Read/Write Demo](https://anttikotajarvi.github.io/modbus-webserial/examples/basic-demo/)
89
+ Simple page to connect, read two registers, and write two registers.
90
+ * [64‑Register Smoke Test](https://anttikotajarvi.github.io/modbus-webserial/examples/smoke-test/)
91
+ Automated loop testing read/write of 64 registers, coils, and discrete inputs with live counters and error logging.
92
+
93
+ ## Current state
94
+
95
+ * **v0.9.0**: Full passing tests, smoke test passed, complete README, build scripts in place
96
+ * **Beta**: Full Modbus RTU function‑code coverage
97
+ * **Alpha**: Basic structure and layout
98
+
99
+ ## Roadmap
100
+
101
+ * **v1.0.0**: Finalize API, apply bug fixes, refine docs, production-ready release
102
+
103
+ ---
104
+
105
+ © 2025 Antti Kotajärvi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modbus-webserial",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Tiny TypeScript library for speaking Modbus-RTU from the browser via Web Serial",
5
5
  "type": "module",
6
6
  "author": "Antti Kotajärvi <antti.kotajarvi@hotmail.com>",
@@ -32,7 +32,7 @@
32
32
  "LICENSE"
33
33
  ],
34
34
  "scripts": {
35
- "build": "tsup src/index.ts --format esm --dts",
35
+ "build": "tsup src/index.ts --format esm --dts --out-dir dist",
36
36
  "test": "vitest run",
37
37
  "test:watch": "vitest",
38
38
  "serve:examples": "npx serve examples",