morkai / h5.modbus

Implementation of the MODBUS IP/ASCII/RTU master and slave over TCP/UDP/Serial for Node.js.
https://miracle.systems/p/h5.modbus
MIT License
28 stars 21 forks source link

TCP Connection to different than localhost #27

Closed rwenergy closed 4 years ago

rwenergy commented 6 years ago

TCPConnection.js

this.socketOptions = Object.assign( {}, options.TcpConnection.socketOptions);
//this.socketOptions = Object.assign({port: 502, host: 'localhost'}, options.socketOptions);

I had to add this in my branch to connect to any other host than localhost. Is this a bug or feature?

morkai commented 6 years ago

You shouldn't change anything if you want to connect to a different host. Just specify it in the connection's options:

const master = modbus.createMaster({
  connection: {
    type: 'tcp',
    socketOptions: {
      host: 'not-localhost.com',
      port: 502
    }
  }
});