andresarmento / modbus-arduino

A library that allows your Arduino to communicate via Modbus protocol, acting as a slave (master in development). Supports serial (RS-232, RS-485) and IP via Ethernet (Modbus IP).
BSD 3-Clause "New" or "Revised" License
453 stars 267 forks source link

The result is an error. #42

Open acabia opened 5 years ago

acabia commented 5 years ago

I am doing a coding test using Arduino board. Unwanted results occur during testing. If you try to read data remotely after inserting m_Modbus.Ists value, an error occurs in multiples of 8. I think that the Modbus.cpp file contains an error in the void Modbus :: readInputStatus () function. please check. di-error2 di error 1

Temporarily modifying and testing as below.

`#if 0 while (numregs--) { i = (totregs - numregs) / 8; if (this->Ists(startreg)) bitSet(_frame[2+i], bitn); else bitClear(_frame[2+i], bitn); //increment the bit index bitn++; if (bitn == 8) bitn = 0; //increment the register startreg++; }

else

do{
  i = (totregs - numregs) / 8;
  if (this->Ists(startreg))
    bitSet(_frame[2+i], bitn);
  else
    bitClear(_frame[2+i], bitn);
  //increment the bit index
  bitn++;
  if (bitn == 8) bitn = 0;
  //increment the register
  startreg++;
} while (numregs--);

endif`

di-ok

ESP-O-MAT commented 4 years ago

Related to this issue: https://github.com/andresarmento/modbus-arduino/issues/35