smarmengol / Modbus-Master-Slave-for-Arduino

Modbus Master-Slave library for Arduino
GNU Lesser General Public License v2.1
473 stars 328 forks source link

Timeout error advanced master #26

Closed vrusu7 closed 7 years ago

vrusu7 commented 7 years ago

I think in your example case 1 …… if (u8query > 2) u8query = 0; must be
if (u8query == 2) u8query = 0; or if (u8query > 1) u8query = 0;

smarmengol commented 7 years ago

The code works as it is written. I checked it.

After sending any query, the Master waits for the slave answer. This implies that the slave must be able to process the query, arrange an answer and send it through the serial port.

El dia 9 ag. 2017 08:58, "vrusu7" notifications@github.com va escriure:

I think in your example case 1 …… if (u8query > 2) u8query = 0; must be if (u8query == 2) u8query = 0; or if (u8query > 1) u8query = 0;

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino/issues/26, or mute the thread https://github.com/notifications/unsubscribe-auth/AANq5c0XU35y1oHBzjwGrZKYi15V1WwSks5sWVh_gaJpZM4Oxq8m .

vrusu7 commented 7 years ago

Your code work fine, I used this class in my project to realize communication between two arduino via RS485 and monitor error state, so thank you very much for your work. About my issue: I use Slave Arduino Nano -> RS485 -> RS485 -> Master Arduino Uno In master I put LCD an print count of Output, Input, Error and last Error messages. When used if (u8query > 2) u8query = 0; code work but we have around 30% of timeout errors, so I examined code step by step with statement of u8state, u8query and I found in this case master try send undefined third element of array telegram[2] (array declare only two elements telegram[0], telegram[1] ) and we have timeout error. I modify if (u8query > 2) u8query = 0; to if (u8query == 2) u8query = 0; and code work fine without any errors.

smarmengol commented 7 years ago

I checked it like you with two arduinos. I don't understand what may be wrong.

Anyway replace the "==" with an ">=". It shall be safer for your code.

El dia 11/08/2017 7:06 a. m., "vrusu7" notifications@github.com va escriure:

Your code work fine, I used this class in my project to realize communication between two arduino via RS485 and monitor error state, so thank you very much for your work. About my issue: I use Slave Arduino Nano -> RS485 -> RS485 -> Master Arduino Uno In master I put LCD an print count of Output, Input, Error and last Error messages. When used if (u8query > 2) u8query = 0; code work but we have around 30% of timeout errors, so I examined code step by step with statement of u8state, u8query and I found in this case master try send undefined third element of array telegram[2] (array declare only two elements telegram[0], telegram[1] ) and we have timeout error. I modify if (u8query > 2) u8query = 0; to if (u8query == 2) u8query = 0; and code work fine without any errors.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino/issues/26#issuecomment-321732734, or mute the thread https://github.com/notifications/unsubscribe-auth/AANq5RqHHotUopr1L6o8lvp_rKZZoAHqks5sW-FXgaJpZM4Oxq8m .