You don’t necessarily need to do it directly from the response handler itslef;
But the response handler is the one and only thing that confirms that you have received the response - so it clearly has to be used to control the process…
BTW: you are only checking for the “+WIMEI” success result - what happens if the command should fail for some reason…?
If it fails, then i have problems… But i guess a reset would be the most economical way to solve that problem since developing for the wavecom modem is not proving to be straight forward and predictable…
What way would you suggest solving this problem and doing things in the correct sequence?
We have a very similar problem and have tried several methods (including those in this thread and others) in search of a solution. No matter our approach, we always seem to get the response from the event handler after the main code has executed. Does anyone have a working solution or a new approach to solving this problem?
Trigger start of your service from the response handler (you can call it directly, you can send message, set event, etc…)
If your application must wait for the response, why do you bother with guessing? Response handler will be called when data is ready.
I am impressed by the willingness of some people to help!
I have an application similar to yours … maybe the correct solution, or one of them, is to use semaphoring. Ask for IMEI set the semaphore red. TCP routine will check the semaphore and if it is red will wait and check again.
If you get a proper IMEI in routine 1 you turn green the semaphore. If you get an error you turn it yellow (so that TCP is not stuck but also now that data is uncorrect). And to be sure to be sure you can set up a timer that if after a while the semaphore is still red you will force it yellow.
But … if it suits you (it does for me) you can simply save the IMEI in flash (it doesn’t change, does it) and only the first time and only if step 2 occours before step 1 … you will have a blank one … and still you could issue a timer to autorelaunch step 2.
I hope I was not too concise … otherwise I can post some code