We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There is an error in the Modbus library's Modbus.cpp file, specifically in the Modbus::writeMultipleRegisters function.
Old Code:
void Modbus::writeMultipleRegisters(byte* frame,word startreg, word numoutputs, byte bytecount) { //Check value if (numoutputs < 0x0001 || numoutputs > 0x007B || bytecount != 2 * numoutputs) { this->exceptionResponse(MB_FC_WRITE_REGS, MB_EX_ILLEGAL_VALUE); return; } //Check Address (startreg...startreg + numregs) for (int k = 0; k < numoutputs; k++) { if (!this->searchRegister(startreg + 40001 + k)) { this->exceptionResponse(MB_FC_WRITE_REGS, MB_EX_ILLEGAL_ADDRESS); return; } } //Clean frame buffer free(_frame); _len = 5; _frame = (byte *) malloc(_len); if (!_frame) { this->exceptionResponse(MB_FC_WRITE_REGS, MB_EX_SLAVE_FAILURE); return; } _frame[0] = MB_FC_WRITE_REGS; _frame[1] = startreg >> 8; _frame[2] = startreg & 0x00FF; _frame[3] = numoutputs >> 8; _frame[4] = numoutputs & 0x00FF; word val; word i = 0; while(numoutputs--) { val = (word)frame[6+i*2] << 8 | (word)frame[7+i*2]; this->Hreg(startreg + i, val); i++; } _reply = MB_REPLY_NORMAL; }
New Code:
void Modbus::writeMultipleRegisters(byte* frame,word startreg, word numoutputs, byte bytecount) { //Check value if (numoutputs < 0x0001 || numoutputs > 0x007B || bytecount != 2 * numoutputs) { this->exceptionResponse(MB_FC_WRITE_REGS, MB_EX_ILLEGAL_VALUE); return; } //Check Address (startreg...startreg + numregs) for (int k = 0; k < numoutputs; k++) { if (!this->searchRegister(startreg + 40001 + k)) { this->exceptionResponse(MB_FC_WRITE_REGS, MB_EX_ILLEGAL_ADDRESS); return; } } _len = 5; _frame = (byte *) malloc(_len); if (!_frame) { this->exceptionResponse(MB_FC_WRITE_REGS, MB_EX_SLAVE_FAILURE); return; } _frame[0] = MB_FC_WRITE_REGS; _frame[1] = startreg >> 8; _frame[2] = startreg & 0x00FF; _frame[3] = numoutputs >> 8; _frame[4] = numoutputs & 0x00FF; word val; word i = 0; while(numoutputs--) { val = (word)frame[6+i*2] << 8 | (word)frame[7+i*2]; this->Hreg(startreg + i, val); i++; } _reply = MB_REPLY_NORMAL; //Clean frame buffer free(_frame); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
There is an error in the Modbus library's Modbus.cpp file, specifically in the Modbus::writeMultipleRegisters function.
Old Code:
New Code:
The text was updated successfully, but these errors were encountered: