@iobroker/modbus 7.0.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.
- package/LICENSE +21 -0
- package/README.md +40 -0
- package/build/convert.d.ts +2 -0
- package/build/convert.js +102 -0
- package/build/convert.js.map +1 -0
- package/build/index.d.ts +88 -0
- package/build/index.js +1005 -0
- package/build/index.js.map +1 -0
- package/build/lib/Master.d.ts +27 -0
- package/build/lib/Master.js +811 -0
- package/build/lib/Master.js.map +1 -0
- package/build/lib/Put.d.ts +19 -0
- package/build/lib/Put.js +113 -0
- package/build/lib/Put.js.map +1 -0
- package/build/lib/Slave.d.ts +15 -0
- package/build/lib/Slave.js +545 -0
- package/build/lib/Slave.js.map +1 -0
- package/build/lib/common.d.ts +3 -0
- package/build/lib/common.js +371 -0
- package/build/lib/common.js.map +1 -0
- package/build/lib/crc16modbus.d.ts +1 -0
- package/build/lib/crc16modbus.js +33 -0
- package/build/lib/crc16modbus.js.map +1 -0
- package/build/lib/jsmodbus/modbus-client-core.d.ts +78 -0
- package/build/lib/jsmodbus/modbus-client-core.js +528 -0
- package/build/lib/jsmodbus/modbus-client-core.js.map +1 -0
- package/build/lib/jsmodbus/modbus-server-core.d.ts +33 -0
- package/build/lib/jsmodbus/modbus-server-core.js +363 -0
- package/build/lib/jsmodbus/modbus-server-core.js.map +1 -0
- package/build/lib/jsmodbus/transports/errors.d.ts +7 -0
- package/build/lib/jsmodbus/transports/errors.js +40 -0
- package/build/lib/jsmodbus/transports/errors.js.map +1 -0
- package/build/lib/jsmodbus/transports/modbus-client-serial.d.ts +23 -0
- package/build/lib/jsmodbus/transports/modbus-client-serial.js +154 -0
- package/build/lib/jsmodbus/transports/modbus-client-serial.js.map +1 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp-rtu.d.ts +24 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp-rtu.js +166 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp-rtu.js.map +1 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp-ssl.d.ts +34 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp-ssl.js +138 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp-ssl.js.map +1 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp.d.ts +27 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp.js +123 -0
- package/build/lib/jsmodbus/transports/modbus-client-tcp.js.map +1 -0
- package/build/lib/jsmodbus/transports/modbus-server-serial.d.ts +29 -0
- package/build/lib/jsmodbus/transports/modbus-server-serial.js +206 -0
- package/build/lib/jsmodbus/transports/modbus-server-serial.js.map +1 -0
- package/build/lib/jsmodbus/transports/modbus-server-tcp.d.ts +25 -0
- package/build/lib/jsmodbus/transports/modbus-server-tcp.js +112 -0
- package/build/lib/jsmodbus/transports/modbus-server-tcp.js.map +1 -0
- package/build/lib/loggingUtils.d.ts +11 -0
- package/build/lib/loggingUtils.js +37 -0
- package/build/lib/loggingUtils.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_events_1 = require("node:events");
|
|
7
|
+
const Put_1 = __importDefault(require("../Put"));
|
|
8
|
+
const ExceptionMessage = {
|
|
9
|
+
0x01: 'ILLEGAL FUNCTION',
|
|
10
|
+
0x02: 'ILLEGAL DATA ADDRESS',
|
|
11
|
+
0x03: 'ILLEGAL DATA VALUE',
|
|
12
|
+
0x04: 'SLAVE DEVICE FAILURE',
|
|
13
|
+
0x05: 'ACKNOWLEDGE',
|
|
14
|
+
0x06: 'SLAVE DEVICE BUSY',
|
|
15
|
+
0x08: 'MEMORY PARITY ERROR',
|
|
16
|
+
0x0a: 'GATEWAY PATH UNAVAILABLE',
|
|
17
|
+
0x0b: 'GATEWAY TARGET DEVICE FAILED TO RESPOND',
|
|
18
|
+
};
|
|
19
|
+
class ModbusClientCore extends node_events_1.EventEmitter {
|
|
20
|
+
log;
|
|
21
|
+
responseHandler = {};
|
|
22
|
+
currentRequest = null;
|
|
23
|
+
reqFifo = [];
|
|
24
|
+
timeout;
|
|
25
|
+
currentState = 'init';
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super();
|
|
28
|
+
this.log = options.logger;
|
|
29
|
+
this.timeout ||= options.timeout || 5 * 1000; // 5s
|
|
30
|
+
this.on('data', this.onData);
|
|
31
|
+
this.on('newState_ready', this.flush);
|
|
32
|
+
this.on('newState_closed', this.onClosed);
|
|
33
|
+
this.responseHandler = {
|
|
34
|
+
1: this.#onReadCoils,
|
|
35
|
+
2: this.#onReadDiscreteInputs,
|
|
36
|
+
3: this.#onReadHoldingRegisters,
|
|
37
|
+
4: this.#onReadInputRegisters,
|
|
38
|
+
5: this.#onWriteSingleCoil,
|
|
39
|
+
6: this.#onWriteSingleRegister,
|
|
40
|
+
15: this.#onWriteMultipleCoils,
|
|
41
|
+
16: this.#onWriteMultipleRegisters,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
inState(state) {
|
|
45
|
+
return this.currentState === state;
|
|
46
|
+
}
|
|
47
|
+
getState() {
|
|
48
|
+
return this.currentState;
|
|
49
|
+
}
|
|
50
|
+
setState(newState) {
|
|
51
|
+
const oldState = this.currentState;
|
|
52
|
+
this.currentState = newState;
|
|
53
|
+
this.emit('stateChanged', oldState, newState);
|
|
54
|
+
this.emit(`newState_${newState}`);
|
|
55
|
+
}
|
|
56
|
+
flush = () => {
|
|
57
|
+
if (this.reqFifo.length) {
|
|
58
|
+
this.currentRequest = this.reqFifo.shift();
|
|
59
|
+
this.currentRequest.timeout = setTimeout(() => {
|
|
60
|
+
this.currentRequest.timeout = undefined;
|
|
61
|
+
this.currentRequest.cb?.({ message: 'timeout', timeout: this.timeout });
|
|
62
|
+
this.emit('trashCurrentRequest');
|
|
63
|
+
this.log.error('Request timed out.');
|
|
64
|
+
this.setState('error');
|
|
65
|
+
}, this.timeout);
|
|
66
|
+
this.setState('waiting');
|
|
67
|
+
this.emit('send', this.currentRequest.pdu, this.currentRequest.unitId);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
onClosed() {
|
|
71
|
+
if (this.currentRequest) {
|
|
72
|
+
this.log.debug('Clearing timeout of the current request.');
|
|
73
|
+
if (this.currentRequest.timeout) {
|
|
74
|
+
clearTimeout(this.currentRequest.timeout);
|
|
75
|
+
this.currentRequest.timeout = undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
this.log.debug('Cleaning up request fifo.');
|
|
79
|
+
this.reqFifo = [];
|
|
80
|
+
}
|
|
81
|
+
handleErrorPDU(pdu) {
|
|
82
|
+
const errorCode = pdu.readUInt8(0);
|
|
83
|
+
// if error code is smaller than 0x80
|
|
84
|
+
// ths pdu describes no error
|
|
85
|
+
if (errorCode < 0x80) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
// pdu describes an error
|
|
89
|
+
const exceptionCode = pdu.readUInt8(1);
|
|
90
|
+
const message = ExceptionMessage[exceptionCode];
|
|
91
|
+
const err = {
|
|
92
|
+
errorCode,
|
|
93
|
+
exceptionCode,
|
|
94
|
+
message,
|
|
95
|
+
};
|
|
96
|
+
// call the desired deferred
|
|
97
|
+
this.currentRequest?.cb(err);
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Handle the incoming data, cut out the packet and send the pdu to the listener
|
|
102
|
+
*/
|
|
103
|
+
onData = (pdu, unitId) => {
|
|
104
|
+
if (!this.currentRequest) {
|
|
105
|
+
this.log.debug('No current request.');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (this.currentRequest.timeout) {
|
|
109
|
+
clearTimeout(this.currentRequest.timeout);
|
|
110
|
+
this.currentRequest.timeout = undefined;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
// check pdu for error
|
|
114
|
+
if (this.handleErrorPDU(pdu)) {
|
|
115
|
+
this.log.debug('Received pdu describes an error.');
|
|
116
|
+
this.currentRequest = null;
|
|
117
|
+
this.setState('ready');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// ignore
|
|
123
|
+
}
|
|
124
|
+
// handle pdu
|
|
125
|
+
const handler = this.responseHandler[this.currentRequest.fc];
|
|
126
|
+
if (!handler) {
|
|
127
|
+
this.log.warn(`Found no handler for fc ${this.currentRequest.fc}`);
|
|
128
|
+
throw new Error(`No handler implemented for fc ${this.currentRequest.fc}`);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
handler(unitId, pdu, this.currentRequest.cb);
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
this.log.warn(`Error in handler for FC${this.currentRequest.fc}: ${err}`);
|
|
135
|
+
}
|
|
136
|
+
this.setState('ready');
|
|
137
|
+
};
|
|
138
|
+
queueRequest = (unitId, fc, pdu, cb) => {
|
|
139
|
+
this.reqFifo.push({ unitId, fc, pdu, cb });
|
|
140
|
+
if (this.inState('ready')) {
|
|
141
|
+
this.flush();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
// FC 1 - Read Coils
|
|
145
|
+
#onReadCoils = (unitId, pdu, cb) => {
|
|
146
|
+
const fc = pdu.readUInt8(0);
|
|
147
|
+
// Check if this is an error response (FC + 0x80)
|
|
148
|
+
if (fc === 1 + 0x80) {
|
|
149
|
+
// This is a ModBus error response for ReadCoils
|
|
150
|
+
const exceptionCode = pdu.readUInt8(1);
|
|
151
|
+
const message = ExceptionMessage[exceptionCode] || `Unknown exception code: ${exceptionCode}`;
|
|
152
|
+
cb({
|
|
153
|
+
errorCode: fc,
|
|
154
|
+
exceptionCode,
|
|
155
|
+
message: `ReadCoils: ${message}`,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else if (fc !== 1) {
|
|
159
|
+
cb({ message: `ReadCoils: Invalid FC ${fc}` });
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
const byteCount = pdu.readUInt8(1);
|
|
163
|
+
// let bitCount = byteCount * 8;
|
|
164
|
+
const resp = {
|
|
165
|
+
unitId,
|
|
166
|
+
fc,
|
|
167
|
+
byteCount,
|
|
168
|
+
payload: pdu.slice(2),
|
|
169
|
+
data: [],
|
|
170
|
+
};
|
|
171
|
+
let counter = 0;
|
|
172
|
+
for (let i = 0; i < byteCount; i += 1) {
|
|
173
|
+
let h = 1;
|
|
174
|
+
const cur = pdu.readUInt8(2 + i);
|
|
175
|
+
for (let j = 0; j < 8; j++) {
|
|
176
|
+
resp.data[counter] = (cur & h) > 0;
|
|
177
|
+
h = h << 1;
|
|
178
|
+
counter += 1;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
cb(null, resp);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
readCoils = (unitId, start, quantity) => {
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
const pdu = new Put_1.default().word8(1).word16be(start).word16be(quantity).buffer();
|
|
187
|
+
this.queueRequest(unitId, 1, pdu, (err, resp) => {
|
|
188
|
+
if (err) {
|
|
189
|
+
reject(new Error(err.message));
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
resolve(resp);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
// FC 2 - Read Discrete Inputs
|
|
198
|
+
#onReadDiscreteInputs = (unitId, pdu, cb) => {
|
|
199
|
+
const fc = pdu.readUInt8(0);
|
|
200
|
+
// Check if this is an error response (FC + 0x80)
|
|
201
|
+
if (fc === 2 + 0x80) {
|
|
202
|
+
// This is a ModBus error response for ReadDiscreteInputs
|
|
203
|
+
const exceptionCode = pdu.readUInt8(1);
|
|
204
|
+
const message = ExceptionMessage[exceptionCode] || `Unknown exception code: ${exceptionCode}`;
|
|
205
|
+
cb({
|
|
206
|
+
errorCode: fc,
|
|
207
|
+
exceptionCode,
|
|
208
|
+
message: `ReadDiscreteInputs: ${message}`,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
else if (fc !== 2) {
|
|
212
|
+
cb({ message: `ReadDiscreteInputs: Invalid FC ${fc}` });
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
const byteCount = pdu.readUInt8(1);
|
|
216
|
+
let counter = 0;
|
|
217
|
+
const resp = {
|
|
218
|
+
unitId,
|
|
219
|
+
fc,
|
|
220
|
+
byteCount,
|
|
221
|
+
payload: pdu.slice(2),
|
|
222
|
+
data: [],
|
|
223
|
+
};
|
|
224
|
+
for (let i = 0; i < byteCount; i++) {
|
|
225
|
+
let h = 1;
|
|
226
|
+
const cur = pdu.readUInt8(2 + i);
|
|
227
|
+
for (let j = 0; j < 8; j += 1) {
|
|
228
|
+
resp.data[counter] = (cur & h) > 0;
|
|
229
|
+
h = h << 1;
|
|
230
|
+
counter += 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
cb(null, resp);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
readDiscreteInputs = (unitId, start, quantity) => {
|
|
237
|
+
return new Promise((resolve, reject) => {
|
|
238
|
+
if (quantity > 2000) {
|
|
239
|
+
return reject(new Error('quantity is too big'));
|
|
240
|
+
}
|
|
241
|
+
const pdu = new Put_1.default().word8be(2).word16be(start).word16be(quantity).buffer();
|
|
242
|
+
this.queueRequest(unitId, 2, pdu, (err, resp) => {
|
|
243
|
+
if (err) {
|
|
244
|
+
reject(new Error(err.message));
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
resolve(resp);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
// FC 3 - Read Holding Registers
|
|
253
|
+
#onReadHoldingRegisters = (unitId, pdu, cb) => {
|
|
254
|
+
const fc = pdu.readUInt8(0);
|
|
255
|
+
// Check if this is an error response (FC + 0x80)
|
|
256
|
+
if (fc === 3 + 0x80) {
|
|
257
|
+
// This is a ModBus error response for ReadHoldingRegisters
|
|
258
|
+
const exceptionCode = pdu.readUInt8(1);
|
|
259
|
+
const message = ExceptionMessage[exceptionCode] || `Unknown exception code: ${exceptionCode}`;
|
|
260
|
+
cb({
|
|
261
|
+
errorCode: fc,
|
|
262
|
+
exceptionCode,
|
|
263
|
+
message: `ReadHoldingRegisters: ${message}`,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
else if (fc !== 3) {
|
|
267
|
+
cb({ message: `ReadHoldingRegisters: Invalid FC ${fc}` });
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
const byteCount = pdu.readUInt8(1);
|
|
271
|
+
const resp = {
|
|
272
|
+
unitId,
|
|
273
|
+
fc,
|
|
274
|
+
byteCount,
|
|
275
|
+
payload: pdu.slice(2),
|
|
276
|
+
register: [],
|
|
277
|
+
};
|
|
278
|
+
const registerCount = byteCount / 2;
|
|
279
|
+
for (let i = 0; i < registerCount; i++) {
|
|
280
|
+
resp.register.push(pdu.readUInt16BE(2 + i * 2));
|
|
281
|
+
}
|
|
282
|
+
cb(null, resp);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
readHoldingRegisters = (unitId, start, quantity) => {
|
|
286
|
+
return new Promise((resolve, reject) => {
|
|
287
|
+
const pdu = new Put_1.default().word8be(3).word16be(start).word16be(quantity).buffer();
|
|
288
|
+
this.queueRequest(unitId, 3, pdu, (err, resp) => {
|
|
289
|
+
if (err) {
|
|
290
|
+
reject(new Error(err.message));
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
resolve(resp);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
// FC 4 - Read Input Registers
|
|
299
|
+
#onReadInputRegisters = (unitId, pdu, cb) => {
|
|
300
|
+
const fc = pdu.readUInt8(0);
|
|
301
|
+
// Check if this is an error response (FC + 0x80)
|
|
302
|
+
if (fc === 4 + 0x80) {
|
|
303
|
+
// This is a ModBus error response for ReadInputRegisters
|
|
304
|
+
const exceptionCode = pdu.readUInt8(1);
|
|
305
|
+
const message = ExceptionMessage[exceptionCode] || `Unknown exception code: ${exceptionCode}`;
|
|
306
|
+
cb({
|
|
307
|
+
errorCode: fc,
|
|
308
|
+
exceptionCode,
|
|
309
|
+
message: `ReadInputRegisters: ${message}`,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
else if (fc !== 4) {
|
|
313
|
+
cb({ message: `ReadInputRegisters: Invalid FC ${fc}` });
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
const byteCount = pdu.readUInt8(1);
|
|
317
|
+
const resp = {
|
|
318
|
+
unitId,
|
|
319
|
+
fc,
|
|
320
|
+
byteCount,
|
|
321
|
+
payload: pdu.slice(2),
|
|
322
|
+
register: [],
|
|
323
|
+
};
|
|
324
|
+
const registerCount = byteCount / 2;
|
|
325
|
+
if (byteCount + 2 > pdu.byteLength) {
|
|
326
|
+
cb({
|
|
327
|
+
message: `ReadInputRegisters: Response length is invalid. Received ${pdu.byteLength} bytes, expected ${byteCount + 2} bytes`,
|
|
328
|
+
});
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
for (let i = 0; i < registerCount; i++) {
|
|
332
|
+
resp.register.push(pdu.readUInt16BE(2 + i * 2));
|
|
333
|
+
}
|
|
334
|
+
cb(null, resp);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
readInputRegisters = (unitId, start, quantity) => {
|
|
338
|
+
return new Promise((resolve, reject) => {
|
|
339
|
+
const pdu = new Put_1.default().word8be(4).word16be(start).word16be(quantity).buffer();
|
|
340
|
+
this.queueRequest(unitId, 4, pdu, (err, resp) => {
|
|
341
|
+
if (err) {
|
|
342
|
+
reject(new Error(err.message));
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
resolve(resp);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
// FC 5 - Write Single Coil
|
|
351
|
+
#onWriteSingleCoil = (unitId, pdu, cb) => {
|
|
352
|
+
const fc = pdu.readUInt8(0);
|
|
353
|
+
const outputAddress = pdu.readUInt16BE(1);
|
|
354
|
+
const outputValue = pdu.readUInt16BE(3);
|
|
355
|
+
const resp = {
|
|
356
|
+
unitId,
|
|
357
|
+
fc,
|
|
358
|
+
outputAddress,
|
|
359
|
+
outputValue: outputValue === 0x0000 ? false : outputValue === 0xff00 ? true : undefined,
|
|
360
|
+
};
|
|
361
|
+
if (fc !== 5) {
|
|
362
|
+
cb({ message: `WriteSingleCoil: Invalid FC ${fc}` });
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
cb(null, resp);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
writeSingleCoil = (unitId, address, value) => {
|
|
369
|
+
return new Promise((resolve, reject) => {
|
|
370
|
+
const payload = value instanceof Buffer ? value.readUInt8(0) > 0 : value;
|
|
371
|
+
const pdu = new Put_1.default()
|
|
372
|
+
.word8be(5)
|
|
373
|
+
.word16be(address)
|
|
374
|
+
.word16be(payload ? 0xff00 : 0x0000);
|
|
375
|
+
this.queueRequest(unitId, 5, pdu.buffer(), (err, resp) => {
|
|
376
|
+
if (err) {
|
|
377
|
+
reject(new Error(err.message));
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
resolve(resp);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
// FC 6 - Write Single Register
|
|
386
|
+
#onWriteSingleRegister = (unitId, pdu, cb) => {
|
|
387
|
+
const fc = pdu.readUInt8(0);
|
|
388
|
+
const registerAddress = pdu.readUInt16BE(1);
|
|
389
|
+
const registerValue = pdu.readUInt16BE(3);
|
|
390
|
+
const resp = {
|
|
391
|
+
unitId,
|
|
392
|
+
fc,
|
|
393
|
+
registerAddress,
|
|
394
|
+
registerValue,
|
|
395
|
+
registerAddressRaw: pdu.slice(1, 2),
|
|
396
|
+
registerValueRaw: pdu.slice(3, 2),
|
|
397
|
+
};
|
|
398
|
+
if (fc !== 6) {
|
|
399
|
+
cb({ message: `WriteSingleRegister: Invalid FC ${fc}` });
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
cb(null, resp);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
writeSingleRegister = (unitId, address, value) => {
|
|
406
|
+
return new Promise((resolve, reject) => {
|
|
407
|
+
const payload = value instanceof Buffer ? value : new Put_1.default().word16be(value).buffer();
|
|
408
|
+
const pdu = new Put_1.default().word8be(6).word16be(address).put(payload);
|
|
409
|
+
this.queueRequest(unitId, 6, pdu.buffer(), (err, resp) => {
|
|
410
|
+
if (err) {
|
|
411
|
+
reject(new Error(err.message));
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
resolve(resp);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
// FC 15 - Write Multiple Coils
|
|
420
|
+
#onWriteMultipleCoils = (unitId, pdu, cb) => {
|
|
421
|
+
const fc = pdu.readUInt8(0);
|
|
422
|
+
const startAddress = pdu.readUInt16BE(1);
|
|
423
|
+
const quantity = pdu.readUInt16BE(3);
|
|
424
|
+
const resp = {
|
|
425
|
+
unitId,
|
|
426
|
+
fc,
|
|
427
|
+
startAddress,
|
|
428
|
+
quantity,
|
|
429
|
+
};
|
|
430
|
+
if (fc !== 15) {
|
|
431
|
+
cb({ message: `WriteMultipleCoils: Invalid FC ${fc}` });
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
cb(null, resp);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
writeMultipleCoils = (unitId, startAddress, data, N) => {
|
|
438
|
+
return new Promise((resolve, reject) => {
|
|
439
|
+
const pdu = new Put_1.default().word8(15).word16be(startAddress);
|
|
440
|
+
if (data instanceof Buffer) {
|
|
441
|
+
pdu.word16be(N).word8(data.length).put(data);
|
|
442
|
+
}
|
|
443
|
+
else if (data instanceof Array) {
|
|
444
|
+
if (data.length > 1968) {
|
|
445
|
+
reject(new Error('Length is too big'));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
const byteCount = Math.ceil(data.length / 8);
|
|
449
|
+
let curByte = 0;
|
|
450
|
+
let cntr = 0;
|
|
451
|
+
pdu.word16be(data.length).word8(byteCount);
|
|
452
|
+
for (let i = 0; i < data.length; i++) {
|
|
453
|
+
curByte += data[i] ? Math.pow(2, cntr) : 0;
|
|
454
|
+
cntr = (cntr + 1) % 8;
|
|
455
|
+
if (cntr === 0 || i === data.length - 1) {
|
|
456
|
+
pdu.word8(curByte);
|
|
457
|
+
curByte = 0;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
this.queueRequest(unitId, 15, pdu.buffer(), (err, resp) => {
|
|
462
|
+
if (err) {
|
|
463
|
+
reject(new Error(err.message));
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
resolve(resp);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
};
|
|
471
|
+
// FC 16 - Write Multiple Registers
|
|
472
|
+
#onWriteMultipleRegisters = (unitId, pdu, cb) => {
|
|
473
|
+
const fc = pdu.readUInt8(0);
|
|
474
|
+
if (fc !== 16) {
|
|
475
|
+
cb({ message: `WriteMultipleRegisters: Invalid FC ${fc}` });
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
const startAddress = pdu.readUInt16BE(1);
|
|
479
|
+
const quantity = pdu.readUInt16BE(3);
|
|
480
|
+
const resp = {
|
|
481
|
+
unitId,
|
|
482
|
+
fc,
|
|
483
|
+
startAddress,
|
|
484
|
+
quantity,
|
|
485
|
+
};
|
|
486
|
+
cb(null, resp);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
writeMultipleRegisters = (unitId, startAddress, data) => {
|
|
490
|
+
return new Promise((resolve, reject) => {
|
|
491
|
+
const pdu = new Put_1.default().word8(16).word16be(startAddress);
|
|
492
|
+
if (data instanceof Buffer) {
|
|
493
|
+
if (data.length / 2 > 0x007b) {
|
|
494
|
+
reject(new Error('Length is too big'));
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
pdu.word16be(data.length / 2)
|
|
498
|
+
.word8(data.length)
|
|
499
|
+
.put(data);
|
|
500
|
+
}
|
|
501
|
+
else if (data instanceof Array) {
|
|
502
|
+
if (data.length > 0x007b) {
|
|
503
|
+
reject(new Error('Length is too big'));
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const byteCount = Math.ceil(data.length * 2);
|
|
507
|
+
pdu.word16be(data.length).word8(byteCount);
|
|
508
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
509
|
+
pdu.word16be(data[i]);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
reject(new Error('Invalid data'));
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
this.queueRequest(unitId, 16, pdu.buffer(), (err, resp) => {
|
|
517
|
+
if (err) {
|
|
518
|
+
reject(new Error(err.message));
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
resolve(resp);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
exports.default = ModbusClientCore;
|
|
528
|
+
//# sourceMappingURL=modbus-client-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modbus-client-core.js","sourceRoot":"","sources":["../../../src/lib/jsmodbus/modbus-client-core.ts"],"names":[],"mappings":";;;;;AAAA,6CAA2C;AAC3C,iDAAyB;AAEzB,MAAM,gBAAgB,GAAgC;IAClD,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,sBAAsB;IAC5B,IAAI,EAAE,oBAAoB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C;gBAC/C,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;CACL;AAxkBD,mCAwkBC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
type ModbusFcState = 'init' | 'ready' | 'processing';
|
|
3
|
+
export default class ModbusServerCore extends EventEmitter {
|
|
4
|
+
readonly log: ioBroker.Logger;
|
|
5
|
+
private data;
|
|
6
|
+
private readonly handler;
|
|
7
|
+
private currentState;
|
|
8
|
+
constructor(options: {
|
|
9
|
+
logger: ioBroker.Logger;
|
|
10
|
+
responseDelay?: number;
|
|
11
|
+
coils?: Buffer;
|
|
12
|
+
holding?: Buffer;
|
|
13
|
+
input?: Buffer;
|
|
14
|
+
discrete?: Buffer;
|
|
15
|
+
});
|
|
16
|
+
inState(state: ModbusFcState): boolean;
|
|
17
|
+
getState(): ModbusFcState;
|
|
18
|
+
setState(newState: ModbusFcState): void;
|
|
19
|
+
onData: (pdu: Buffer, callback: (response: Buffer) => void) => void;
|
|
20
|
+
getCoils: () => Buffer;
|
|
21
|
+
getInput: () => Buffer;
|
|
22
|
+
getHolding: () => Buffer;
|
|
23
|
+
getDiscrete: () => Buffer;
|
|
24
|
+
onReadCoils: (pdu: Buffer, cb: (pdu: Buffer, response?: (result: Buffer) => void) => void) => void;
|
|
25
|
+
onReadDiscreteInputs: (pdu: Buffer, cb: (pdu: Buffer, response?: (result: Buffer) => void) => void) => void;
|
|
26
|
+
onReadHoldingRegisters: (pdu: Buffer, cb: (pdu: Buffer, response?: (result: Buffer) => void) => void) => void;
|
|
27
|
+
onReadInputRegisters: (pdu: Buffer, cb: (pdu: Buffer, response?: (result: Buffer) => void) => void) => void;
|
|
28
|
+
onWriteSingleCoil: (pdu: Buffer, cb: (pdu: Buffer, response?: (result: Buffer) => void) => void) => void;
|
|
29
|
+
onWriteSingleRegister: (pdu: Buffer, cb: (pdu: Buffer, response?: (result: Buffer) => void) => void) => void;
|
|
30
|
+
onWriteMultipleCoils: (pdu: Buffer, cb: (pdu: Buffer, response?: (result: Buffer) => void) => void) => void;
|
|
31
|
+
onWriteMultipleRegisters: (pdu: Buffer, cb: (pdu: Buffer, response?: (result: Buffer) => void) => void) => void;
|
|
32
|
+
}
|
|
33
|
+
export {};
|