stephane / modbusino

Small Modbus slave, RTU (serial) for Arduino
http://libmodbus.org
ISC License
143 stars 94 forks source link

Modbusino #4

Closed GregRadion closed 11 years ago

GregRadion commented 11 years ago

I downloaded and started using your Modbusino code for a project and I believe there is a couple of easily fixable bugs that you should be aware of.

  1. i in reply() should be 16 bit not 8, when it is 8 bit the program will lock up if you try and read a register above 255.
  2. nb_reg should also be 16 bit not 8, it is in a number of locations, comes into play when reading registers above 255.
  3. if (address + nb > nb_reg) { rsp_length = response_exception( slave, function, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp); } in reply() should be followed with an else that is closed before send_msg(rsp, rsp_length); As if it is not there the program will still form a reply and you can read memory beyond your register table, this is not desirable.
  4. Checking for Arduino environment 1 is required as WProgram.h has been replaced with Arduino.h
stephane commented 11 years ago

Thank you, I've just added another commit to reindent the code (with new else) and fix a remaining 16 bit bug.