Cloud-Automation / node-modbus

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

readCoils return multiple values #41

Closed mjasnikovs closed 8 years ago

mjasnikovs commented 8 years ago

Code

const modbus = require('jsmodbus')

const client = modbus.client.tcp.complete({
    host: 'JWLE-C45',
    port: 502,
    autoReconnect: true,
    reconnectTimeout: 1000,
    timeout: 5000,
    unitId: 0
})

client.on('connect', () => {
    client.writeSingleCoil(1, true).then(console.log).fail(console.log)
    client.readCoils(1, 1).then(console.log).fail(console.log)
    setTimeout(() => client.close(), 100)
})
client.on('error', console.log)
client.connect()

Result

{ fc: 5, outputAddress: 1, outputValue: true }
{ fc: 1,
  byteCount: 1,
  coils: [ true, false, false, false, false, false, false, false ] }

I write into first coil value "true", and then return value with readCoils(1, 1). Returned value contains 8 values. Is this correct? Or only one value shod be returned.

Sorry, if this is stupid question.

stefanpoeter commented 8 years ago

Not a stupid question!

Since I evaluate 8 bit unsigned values I do not wanted to cut the result down down. Lazy I know but the behavior is accurate.