-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientSeneca.js
More file actions
75 lines (68 loc) · 1.93 KB
/
clientSeneca.js
File metadata and controls
75 lines (68 loc) · 1.93 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const modbus = require("jsmodbus")
const net = require('net')
const socket = new net.Socket()
module.exports = {socket:socket};
const options = {
'host': '10.10.3.220',
'port': '502'
}
//Waiting for connection
var client = new modbus.client.TCP(socket)
socket.on('connect', function () {
console.log("Client connected to " + options.host + ":" + options.port);
setInterval(function () {
//Reading PowerPhase1 Total
// client.readInputRegisters(0, 2)
// .then(function (resp) {
// console.log( resp.response._body)
// }).catch(function () {
// console.error(arguments)
// })
//Reading PowerPhase1 Total Max
client.readHoldingRegisters("AC4D", 10)
.then(function (resp) {
console.log("Timestamp " + Date.now())
console.log(resp.response._body)
console.log("\n")
}).catch(function () {
console.error(arguments)
})
}, 5000)
});
socket.on('readCoils', function () {
let x;
client.readCoils(0, 8)
.then(function (resp) {
x = resp.response
console.log(resp);
return x;
socket.end()
}).catch(function () {
console.error(arguments)
socket.end()
})
return x;
})
socket.on('writeCoil', function () {
let x;
client.writeSingleCoil(17, false)
.then(function (resp) {
console.log(resp)
socket.end()
}).catch(function () {
console.error(arguments)
socket.end()
})
return x;
})
socket.on('error', console.error)
socket.connect(options)
// socket.on('connect', function () {
// setInterval(function () {
// client.readHoldingRegisters(0, 2)
// .then(function (resp) {}).catch(function () {
// console.error(arguments)
// socket.end()
// })
// }, 200)
// })