Write Single Register 0x06 I think it works badly
Closed this issue · 9 comments
Hello
If I use Write Single Register 0x06, I can not send DATA to another Register. Always DATA is saved at Register 0.
If I use Write Multiple Registers 0x10, is all ok!
Is there an error in the library?
Is there an error in the library?
maybe :-)
It will be nice to find it and fix it, if it exist, can you identify the problem and fix it, it will be nice:
Interesting code lines:
https://github.com/yaacov/ArduinoModbusSlave/blob/master/src/ModbusSlave.h#L33
https://github.com/yaacov/ArduinoModbusSlave/blob/master/src/ModbusSlave.h#L35
https://github.com/yaacov/ArduinoModbusSlave/blob/master/src/ModbusSlave.cpp#L163
https://github.com/yaacov/ArduinoModbusSlave/blob/master/src/ModbusSlave.cpp#L311
https://github.com/yaacov/ArduinoModbusSlave/blob/master/src/ModbusSlave.cpp#L337
Thank you for your response..
unfortunately, it's not my league ..
I can not do it;)
it's not my league ..
a - you can try :-)
b - I think the lib is ok ( from looking at the code, didn't try ... ), you can check again on your side, maybe you can see the problem in your code ?
My code:
`uint8_t writeMemory(uint8_t fc, uint16_t address, uint16_t length) {
uint16_t registerIndex;
for (int i = 0; i < length; i++)
{
array_writeMemory[i]=slave.readRegisterFromBuffer(i);
}
temperature1=array_writeMemory[0]/10;
temperature2=array_writeMemory[1]/10;
temperature3=array_writeMemory[2]/10;
return STATUS_OK;`
and i use to testing program QModbus : https://sourceforge.net/projects/qmodbus/files/latest/download
where in your code do you use the address
?
If i use 0x06 write single register only is temperature1 ok in my code.
If i use 0x10 multiple register write temperature1 , 2 ,3 are OK
array_writeMemory[i]=slave.readRegisterFromBuffer(i);
should be:
array_writeMemory[i + address]=slave.readRegisterFromBuffer(i);
?
By removing parts of the program that were not necessary for me, I did not know that the address was needed. You are great! Thank you again for your help. You did a great job!!!