Closed boulirox closed 4 years ago
I've implemented your fix on my fork... Could you test my fork to see if the problem is fixed? https://github.com/dlabun/modbus-arduino
我也发现这个问题了。解决办法如下 byte buffer; uint16_t size = ebox_get_sizeof_ptr(frame - 1); buffer = (byte )ebox_malloc(size); memcpy(buffer,frame,size); . . . uint16_t val; uint16_t i = 0; while(numoutputs--) { val = (((uint16_t)buffer[6 + i 2]) << 8 | (uint16_t)buffer[7 + i 2]); this->Hreg(startreg + i, val); i++; } ebox_free(buffer);
I've implemented your fix on my fork... Could you test my fork to see if the problem is fixed? https://github.com/dlabun/modbus-arduino
你这个方发我实验了下。回复给主机的消息中出现错误信息
Hello,
I found a bug with the write multiple holding registers function. The problem was that the variable was freed before the values were set in the registers. I'm not sure how to commit my fix so here's the code if someone want to do it.
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; }
}