Cloud-Automation / chrome-modbus

Modbus/TCP for Chrome Apps.
MIT License
33 stars 17 forks source link

Connecting the Modbus #3

Open hammadtq opened 8 years ago

hammadtq commented 8 years ago

Hi,

I found an error and struggled with it for a while.

When we acquire a new client via:

var client = new ModbusClient()

The function in modbus.js has:

`ModbusClient = function (timeout, autoreconnect) {

    if (!(this instanceof ModbusClient))
        return new ModbusClient(timeout, autoreconnect);

    // needed for the inheritance
    StateMachine.call(this, 'init');

    var host            = 'localhost',
        port            = 502,
        id              = 0,`

While again, after acquiring the client I am giving host and port:

client.connect(host, port);

After much struggle, I found out that above 'localhost' is creating all the problem. If I change it to the IP address then it works fine. However, I am not sure why library is using an IP there and then also using a different connection function. Can you please have a look?

Great work by the way!