I have got a Wavecom Supreme GSM modem. I wrote a simple application that communicates with the modem and reads text messages it receives.
My application queries the modem for information about the number of messages it stores in its memory and if the number is greater than 0, it reads the messages deleting them from the modem's memory. I query the modem this way every few seconds.
Unfortunately, however, the modem hangs every few minutes and does not respond to any AT commands I send to it. The only solution I came up with to unlock the communication is to close the serial port and open it anew. Then everything is fine for next few minutes after which serial port has to be reopened again when the modem hangs.
It can of course be the modem's fault, but I'm wondering whether the way I communicate with it is OK.
Firs of all, I open the modem's serial port for asynchronous operations. Then I set the DCB structure as follows:
GetCommState(PortHandle, DCB);
DCB.BaudRate := 115200;
DCB.ByteSize := 8;
DCB.Parity := NOPARITY;
DCB.StopBits := ONESTOPBIT;
DCB.EvtChar := #13;
SetCommState(PortHandle, DCB);
SetCommMask(PortHandle, EV_RXFLAG);
//the modem does not respond without setting these:
EscapeCommFunction(PortHandle, SETDTR);
EscapeCommFunction(PortHandle, SETRTS);
And then all I do is send AT commands and wait for modem's response. I do not use any flow control. Everything I do is wait for comm event, read the data from the serial port's queue when the modem responds and write some AT commands followed by the #13 character to query the modem for messages.
I think I may have set the DCB structure improperly, for as you can see, I do not modify some of its fields. Because my knowledge on serial port is not enough, I do not know how to set the RTS and DTR control (enabled/disabled/handshake/toggle).
If you noticed some obvious mistakes in this way of handling modem, I would be grateful if you explained me what I had done wrong. If everything is fine, on the other hand, maybe you have got an idea why the modem hangs?
Thank you in advance.