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

Reading 8 Ists & Coils and writing multiple register bug fix #35

Open umarsaid opened 6 years ago

umarsaid commented 6 years ago

I found some bugs in the library. You reading Ists and Coils for 8 registers, the 8th register will always be 0. Also, when we write multiple holding registers, the last value will be lost.

I have fix the bug in my local copy. I want to submit the bug but I do not know how.

masrodjie commented 6 years ago

you can fork the repo, commit your changes and pull request. or you can attach your update here, i'll try to make pull request to make this library better

janchower commented 6 years ago

I am also seeing this same issue - every 8th coil is not working.
Umarsaid, is there any way at all for you to post or forward me the updated library you mention that you fixed? My programming skills are still improving and I'm having trouble reading through the library to identify where the issue is. Thank you very much in advance for your help!!!!

petersoltys commented 5 years ago

Please would you change these lines 329 and 380 in modbus.cpp from while (numregs--) { i = (totregs - numregs) / 8; to while (numregs) { i = (totregs - numregs) / 8; numregs--; by my findings only this decrement order need to be changed.

janchower commented 5 years ago

Peter - THANK YOU - I tried this and it looks like it works! I am very grateful for your help. This is definitely something very important to my projects. I really appreciate this!

raf59 commented 5 years ago

Thank you Peter !! I met the same issue with the writeMultipleCoils function. I did the same change at line 499 with numoutputs and it works now.

while (numoutputs) { i = (totoutputs - numoutputs) / 8; numoutputs--;

HGQ21102 commented 4 years ago

Thank you Peter !! I met the same issue with the writeMultipleCoils function. I did the same change at line 499 with numoutputs and it works now.

while (numoutputs) { i = (totoutputs - numoutputs) / 8; numoutputs--;

Thank you, you are the best

Please would you change these lines 329 and 380 in modbus.cpp from while (numregs--) { i = (totregs - numregs) / 8; to while (numregs) { i = (totregs - numregs) / 8; numregs--; by my findings only this decrement order need to be changed.

Thank you, you are the best