sclavel / homebridge-modbus

Homebridge plugin to interface with any modbusTCP
8 stars 14 forks source link

Sizing of modbus reads via min/max may cause failures #1

Open sandeen opened 4 years ago

sandeen commented 4 years ago

First off, thanks for this plugin! Super great. :)

I think the optimization around min & max addresses:

    for (let type in this.maxModbus) {
      let idx = this.minModbus[type];
      let count = 1+this.maxModbus[type]-idx;
      this.commands.push({"cmd":'r', "type":type, "add":idx, "count":count});
    }

can cause problems; I have a boiler which has Input Registers at 0,1,2 and 768,769 ... 776.

If I try to configure the plugin to read register 1 as well as register 771, I think this results in an attempt to read 771 bytes from address 1, and because there are many addresses not present, this fails:

error reading modbus { cmd: 'r', type: 'i', add: 1, count: 771 } UserRequestError {
  err: 'ModbusException',
  message: 'A Modbus Exception Occurred - See Response Body',
  response: ModbusTCPResponse {
    _id: 1,
    _protocol: 0,
    _bodyLength: 3,
    _unitId: 1,
    _body: ExceptionResponseBody { _fc: 4, _code: 2 }
  }
}

(Also, as a side note, it might be good to specify whether the plugin assumes addresses which start at 0 or at 1; this seems to be somewhat inconsistent across Modbus documentation, so specifying which is used here might save some trial and error... I think it starts at 1, so you might also want to catch & flag i.e. "i0" as invalid?)

m4rkv5 commented 2 years ago

I have the same issue. Accessory A works and Accessory B but when I add both, i get errors with count nearly 10k.

m4rkv5 commented 2 years ago

This fork has a modbusmode switch: https://github.com/ljia310/homebridge-modbus