Commit 3e30034
authored
Fixes #303 by converting Promise-based service vector callbacks to callback-style
to work around a modbus-serial bug where Promise-based callbacks are not properly
awaited. This resolves "Modbus exception 4: Slave device failure" errors.
Root Cause:
modbus-serial@8.0.23 ServerTCP/ServerSerial does not properly await Promise-based
callbacks for read operations. The library's type definitions claim to support
Promise-based callbacks, but the implementation doesn't actually await them,
causing timeouts and exception 4 errors.
See upstream issue: yaacov/node-modbus-serial#548
Changes:
1. Test that reproduces the bug - Added tcp.async-compat.test.ts and
rtu.async-compat.test.ts with simulateModbusSerialCall helper demonstrating
exact bug behavior
2. Fix implementation - Converted all read operations (getHoldingRegister,
getInputRegister, getMultipleHoldingRegisters, getMultipleInputRegisters,
getCoil, getDiscreteInput) to callback-style in both TCP and RTU transports
3. Refactor test duplication - Extracted callServiceVector helper into shared
test-helpers.ts, removing 80 lines of duplication
4. Fix TypeScript compilation - Corrected callback signatures to match
FCallbackVal<T> type (non-optional value parameter, proper error handling)
5. Increase test coverage - Added 18 tests for error handling and edge cases,
bringing coverage to ~95% statements, ~73% branches, 100% functions
Write operations (setRegister, setRegisterArray, setCoil) remain Promise-based
as they work correctly with modbus-serial.
Testing:
- All 309 tests pass
- New async-compat tests verify fix works with simulated modbus-serial behavior
- No breaking changes to public API
Follow-up issues created: #305, #306, #307, #308
Fixes #303
Related to yaacov/node-modbus-serial#548
1 parent bd591a8 commit 3e30034
9 files changed
Lines changed: 1018 additions & 92 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
82 | 87 | | |
83 | | - | |
| 88 | + | |
84 | 89 | | |
85 | 90 | | |
86 | 91 | | |
87 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
88 | 98 | | |
89 | 99 | | |
90 | 100 | | |
91 | 101 | | |
92 | 102 | | |
93 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
94 | 108 | | |
95 | | - | |
| 109 | + | |
96 | 110 | | |
97 | 111 | | |
98 | 112 | | |
99 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
100 | 119 | | |
101 | 120 | | |
102 | 121 | | |
| |||
118 | 137 | | |
119 | 138 | | |
120 | 139 | | |
121 | | - | |
122 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
123 | 146 | | |
124 | 147 | | |
125 | 148 | | |
126 | 149 | | |
127 | 150 | | |
128 | 151 | | |
129 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
130 | 158 | | |
131 | 159 | | |
132 | 160 | | |
| |||
157 | 185 | | |
158 | 186 | | |
159 | 187 | | |
160 | | - | |
161 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
162 | 194 | | |
163 | 195 | | |
164 | | - | |
165 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
166 | 202 | | |
167 | 203 | | |
168 | 204 | | |
| |||
178 | 214 | | |
179 | 215 | | |
180 | 216 | | |
181 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
182 | 224 | | |
183 | 225 | | |
184 | 226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
76 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
80 | | - | |
81 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
82 | 91 | | |
83 | 92 | | |
84 | 93 | | |
| |||
89 | 98 | | |
90 | 99 | | |
91 | 100 | | |
92 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
93 | 107 | | |
94 | 108 | | |
95 | 109 | | |
| |||
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
104 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
105 | 124 | | |
106 | 125 | | |
107 | 126 | | |
| |||
126 | 145 | | |
127 | 146 | | |
128 | 147 | | |
129 | | - | |
130 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
131 | 154 | | |
132 | 155 | | |
133 | 156 | | |
| |||
141 | 164 | | |
142 | 165 | | |
143 | 166 | | |
144 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
145 | 173 | | |
146 | 174 | | |
147 | 175 | | |
| |||
169 | 197 | | |
170 | 198 | | |
171 | 199 | | |
172 | | - | |
173 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
174 | 206 | | |
175 | | - | |
176 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
177 | 213 | | |
178 | 214 | | |
179 | 215 | | |
| |||
190 | 226 | | |
191 | 227 | | |
192 | 228 | | |
193 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
194 | 236 | | |
195 | 237 | | |
196 | 238 | | |
| |||
0 commit comments