Cloud-Automation / node-modbus

Modbus TCP Client/Server implementation for Node.JS
471 stars 175 forks source link

Examples not working #39

Closed pyxiscloud closed 8 years ago

pyxiscloud commented 8 years ago

Hello trying examples for serial - not working whats wrong?

var ModbusClient = require('jsmodbus'), client = ModbusClient('/dev/ttyUSB0', 9600); client.on('connect', function () { client.writeSingleCoil(4, true).then(function (resp) { console.log(resp); }).fail(function (err) { console.log(err); }).done(function () { client.close(); }); }); client.on('error', function (err) { console.log(err); });

got this: TypeError: ModbusClient is not a function

when i change second to this: client = ModbusClient.createSerialClient('/dev/ttyUSB0', 9600); got this: TypeError: ModbusClient.createSerialClient is not a function

please update examples?

pyxiscloud commented 8 years ago

Second question - how to setup ID of modbus device (serialport)?

stefanpoeter commented 8 years ago

You are using it wrong. Try the following :

var ModbusClient = require('jsmodbus'),
      client = ModbusClient.client.serial.complete({ 'portName' : '/dev/ttyUSB0',  'baudRate' : 9600 });

I will update the examples.

Can you confirm it works? But be aware, the serial code is not done it.

mjasnikovs commented 8 years ago
modbus connected
c:\hub\modbus\boot.js:14
        client.readInputRegister(0, 13)
               ^

TypeError: client.readInputRegister is not a function
    at Object.client.on (c:\hub\modbus\boot.js:14:9)
    at Object.emit (c:\hub\modbus\node_modules\stampit-event-bus\src\stampit-event-bus.js:20:38)
    at Object.<anonymous> (c:\hub\modbus\node_modules\jsmodbus\src\modbus-tcp-client.js:57:18)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1068:10)

Same here, example is not working.

stefanpoeter commented 8 years ago

It should be client.readHoldingRegisterS.

mjasnikovs commented 8 years ago

Pleas update readme "client.readDiscreteInputS" and "client.readInputRegisterS"

Thank you.