问题
How are you supposed to programatically detect when the remote modem on your call hangs up? I am writing a C program which interfaces with a SoftModem device /dev/ttySL0
in Ubuntu linux. I am able to configure the modem using Hayes AT commands and communicate with the remote modem. However, I haven't been able to determine how I'm supposed to detect that the other end has hung up the line.
I have the modem configured so that when the other end hangs up, the device prints NO CARRIER
and switches to command mode. However, I can't use the NO CARRIER
string because I can't guarantee that the modem won't receive that string while in data mode.
How do you "listen" for remote hang up?
回答1:
Testing for NO CARRIER
as text will not suffice. This text frequently occurs on sites in the net, even on Q&A sites.
Coming from the modem, it should be enclosed in line breaks.
Besides, after you detect that text, you can try to switch to command mode with +++
. If that works, your connection persists and you can reattach it and continue using it. If it doesn't (because you are already there and +++
is an invalid command), the connection has gone.
回答2:
This is a hardware signal on modems, the Carrier Detect (CD) line. You'll need to monitor it to know that the connection was lost. Basics in linux are described in this how-to, you obtain the signal state with ioctl() using the TIOCM_CAR command.
来源:https://stackoverflow.com/questions/10253965/hayes-at-commands-detect-remote-hangup