-
Notifications
You must be signed in to change notification settings - Fork 0
/
test3.js
43 lines (24 loc) · 902 Bytes
/
test3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { response } = require("express");
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();
client.connectTCP("192.168.100.101", { port: 502 }, () => {
client.setID(3);
//console.clear();
let writeRegisterId = 23;
let registerId = 41023;
let registerSize = 8;
let buf1 = Buffer.alloc(8);
buf1.writeInt16BE(15, 0);
console.log(buf1);
client.writeRegisters(writeRegisterId, buf1).then((response) => {
console.log(response);
}).catch((err) => { console.log(err) });
setInterval(function() {
client.readInputRegisters(registerId, registerSize).then((response) => {
let buffer = response.buffer;
console.log('\nREAD =>');
//console.log(response);
console.log(buffer.readInt16BE(0));
});
}, 1000);
});