Closed NoobTW closed 7 years ago
Some code please.
var modbus = require('jsmodbus');
// create a modbus client
var client = modbus.client.tcp.complete({
'host' : '192.168.255.2',
'port' : 502,
'autoReconnect' : true,
'reconnectTimeout' : 1000,
'timeout' : 5000,
'unitId' : 0,
'logEnabled': true,
'logLevel': 'debug',
'logTimestamp': true
});
client.connect();
// reconnect with client.reconnect()
client.on('connect', function () {
// make some calls
client.readCoils(0, 13).then(function (resp) {
// resp will look like { fc: 1, byteCount: 20, coils: [ values 0 - 13 ], payload: <Buffer> }
console.log(resp);
}, console.error);
});
client.on('error', function (err) {
console.log(err);
})
2017-03-30T08:44:57.629Z 'DEBUG :' 'Data flushed.' 2017-03-30T08:45:02.636Z 'ERROR :' 'Request timed out.'
Seems like the request is not getting handled. What server are you using?
It's a real hardware, so I'm not really sure what server I'm using.
For further information, below is the code that passed in jsmodbus v0.5.2:
var modbus = require('jsmodbus');
var client = modbus.createTCPClient(502, '192.168.255.2', function(err) {
if (err) {
console.log('Cannot connect to server');
return false;
} else {
console.log('Connected to server');
}
});
client.readCoils(0, 8, function(resp, err) {
if (!err) {
console.log(resp.coils);
} else {
console.log(err);
}
});
Well, thats not much. Can you start wireshark and inspect the tcp packages?
I don't think I can do that because those things are pass through a switch.
But you are executing the client on your local machine, so wireshark is no problem.
Oops, you're right. Because I ran the script remotely on a Raspberry Pi.
HERE is the pcap file I caught using tshark while running jsmodbus.
The way I see it, there is no response coming from your device. Check your devices configuration, Doesn't seem like an error related to this module.
That's weird the device only reply the old version jsmodbus. But thanks, I'll check if it's a device issue.
Hi.
After a few try, I found out that change unitId: 1
then my device will handle it.
Just let you know, and thanks for your help.
I was able to connect and read coils using jsmodbus 0.5.2, but I cannot read coils using this 2.1.0. Below is the log output.
I tried in node v7.8.0 and v6.9.1; both not worked.