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

Connecting over TCP even though I choose serial #12

Closed pakerfeldt closed 7 years ago

pakerfeldt commented 7 years ago

I have been using 0.1.0 for a while but tried to bump to 1.0.0. However, now it seems to try to open a TCP connection even though I have specified a serial port.

This is how I create the master:

var port = new SerialPort(serialPath, { baudrate: baudrate, parity: parity }, false);
  this.modbus = library.createMaster({
    transport: {
      type: 'rtu',
      eofTimeout: 500,
      connection: {
        type: 'serial',
        serialPort: port
      }
    },
    suppressTransactionErrors: false,
    retryOnException: true,
    maxConcurrentRequests: 1,
    defaultUnit: 0,
    defaultMaxRetries: 1,
    defaultTimeout: 1000,
  });

And the log prints:

Master error { [Error: connect ECONNREFUSED 127.0.0.1:502] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 502 }

Am I missing something?

morkai commented 7 years ago

The connection options object should now be specified in the master's options and not the transport's:

var port = new SerialPort(serialPath, { baudrate: baudrate, parity: parity }, false);
  this.modbus = library.createMaster({
    transport: {
      type: 'rtu',
      eofTimeout: 500
    },
    connection: {
      type: 'serial',
      serialPort: port
    },
    suppressTransactionErrors: false,
    retryOnException: true,
    maxConcurrentRequests: 1,
    defaultUnit: 0,
    defaultMaxRetries: 1,
    defaultTimeout: 1000,
  });
pakerfeldt commented 7 years ago

👍