Hello,
I have written a code for modbus communication that uses Arduino serial and software serial library. However, I am facing two issues as below when the code is tried with ModRSsim2 software:
Before that my code simply reads few sets of registers from modbus slave device and forms a single string and sends to cloud.
Problem 1 : In my code, if I comment out the function GSM_Send_HTTP_Data(), then all modbus requests are sent and responses are received for it. However, the order in which the modbus request is sent, is not same as in my code.
Expected sequence :
Request 1 : 01,04,00,0D,00,10... :: Receive response for this packet
Request 2 : 01,04,00,96,00,01... :: Receive response for this packet
Request 3 : 01,04,00,99,00,01... :: Receive response for this packet
Request 4 : 01,04,00,9C,00,01... :: Receive response for this packet
Sequence in communication trace:
Request 1 : 01,04,00,0D,00,10... :: Receive response for this packet
Request 4 : 01,04,00,9C,00,01... :: Receive response for this packet
Request 3 : 01,04,00,99,00,01... :: Receive response for this packet
Request 2 : 01,04,00,96,00,01... :: Receive response for this packet
Problem 2 : If I call GSM_Send_HTTP_Data() in my code, then data exchange happens for only one modbus request 01,04,00,0D,00,10.... It should happen for all four.
I tried checking what is happening inside the function GSM_Send_HTTP_Data() function. I found that if I removed delays and software serial print (mySerial.print()) function statement, then I was able to get response for all four requests that I am sending.
I did not understand this behaviour. Could you please help me out with where I am lagging?
I have attached my newly implemented code and screenshot of communication trace from modRSsim2 software.
Please help me find out what is wrong where!
Please excuse me for blind delays. I have implemented a method to accept only valid data, based on expected number of response bytes. For now, no validation of CRC upon data receipt.
code.c.pdf (23.2 KB)