MODBUS TCP (MgsModbus)

Hello everyone,

Im using the modbus library given here (My Arduino Projects - Website dedicated to my arduino projects - A ModBus TCP library for the Arduino system). I have implemented a project with Arduino Mega as master which is connected to a router and a arduino uno is attached to the same router as slave. I have also built a simple website which is stored on Arduino Mega(master) and using ajax every 2 seconds im uploading a analogue value on the website received from the slave.

First i wait for a ajax call to arrive then i run the function Mb.Req(...) to send request and then the function Mb.MbmRun(); to receive the request. The problem im facing is that on the first run ONLY Mb.Req(..) runs and Mb.MbmRun(); Fails. On second run Mb.Req(...) Fails But Mb.MbmRun(); receives the proper response and it is then displayed. Now this cycle repeats. This pattern changes if i start reading more number of values.

Now this is fast so its fine even if i get a value every 4 seconds. The FLAW is when i added a button on the site now wen i click the button and explicitly i want to run for example Mb.Req() and Mb.Mbmrun() for Coil writing, u never know if this click will work or not as wen u click that time around the modbus might fail.

How could i solve this issue?

I'm working with this library now myself. It might help if you post your sketch here.

I'll let you know if I find anything, if you've fixed your problem it might be nice to post your example code anyway as the author doesn't provide any that I can see.