Modem hang-up time

modemserial

I'm looking for some typical and worst-case times for a serial modem to hang up and DCD deassert after receiving the hang-up command string ("ATH").

My project uses a modem and occasionally must reboot for other reasons. The reboot is fast enough that if I don't wait after sending ATH, DCD is frequently still asserted when the system comes back up and it tries sending application messages to the modem while the previous connection finishes closing.

I can easily wait for DCD to deassert before closing down, but don't want to get stuck in an infinite loop if something goes wrong. How soon should I be able to expect a serial modem to close a connection? After how long can I suppose that something is wrong if DCD is still high after sending a hang-up command?

Best Answer

Two solutions occur to me:

  1. Not knowing the exact worst case, use a generous timeout, like one second. After rebooting, do not do anything with the modem for that long. (Perhaps conditionally: do not do anything with the modem for one second while it is asserting DCD. If it is not asserting DCD, then just proceed, and also bail out of the loop the moment it stops asserting DCD.

  2. Refinement: in some nonvolatile storage which survives reboots, record a flag which says "there is a modem hang-up transaction in progress". Always clear the flag when the modem finishes hanging up. If a reboot happens during a hangup, then upon reboot, if you find this flag, then you know that if the modem is asserting DCD, this is not a valid modem session, but one that is in process of hanging up. The software must wait for DCD to go away. In this (presumably infrequent) case, you can perhaps tolerate a more generous delay.

The delay does not have to affect the full boot sequence, just the startup of the application which communicates with the modem.

Related Topic