At work, we just got a la开发者_运维技巧rge number exotic cellular devices that need to be programmed. To do this, you plug in a standard home telephone and dial a series of numbers, with pauses between them.
To me, this is a task that begs to be automated, and we've got one Linux desktop (a test Asterisk machine) with a modem on it.
So, how can I automate this task?
Simply send the necessary AT commands to your modem via the modem's corresponding /dev
device, e.g. ATDT 12,456567,21
I think you should be able to open the modem device (often sym-linked from /dev/modem), and enter modem codes to reset the modem (atz, perhaps), then the codes to dial (atd), then the number, with "," for pause.
You can automate this in probably almost any language that allows you to write to the device file.
Take a look at the reference here: http://www.zoltrix.com/support_html/modem/USEMODEM.HTM
My typical dial out string (all directed at the modem device):
- ATZ (Dear modem, forget everything you knew)
- ATS11=33 (I liked dialing fast)
- ATF0 (Auto negotiate link speed)
- ATL3 (I like it loud)
- ATM3 (I only like hearing the handshake loudly)
- AT&G(x) (In case you have a US modem and need to use it in the rest of the world (guard tone))
- AT&K3 (hw flow control, if not available use software via AT&K4)
- AT&R1 (CTS (clear to send) is always on. Wrapping RJ-11 connections in static free softener sheets helps this.
Finally, and most importantly:
- ATDT (number) (Dial a number using DTMF) Depending on the age, your modem may support ATDP (pulse dialing).
Just keep in mind, +++
is an escape sequence, returning you to the modem console :) Have fun. +++ ATH0
and you hung up. ATH1
takes it off hook and does little else. ATA
answers an incoming data call. Comma, ,
is a pause.
Yeah, others linked to the Hayes AT command set, I actually used it for years as a SysOp of a BBS :)
Finally, screw Kermit, use Zmodem.
Links: Synchronet, WWiV, the rest are an exercise for the reader, though I humbly suggest searching for Renegade, Telegard, TaG and others.
Oh dear, I'm off on a tangent.
If you need to pause and respond to replies back from the device - this is exactly what expect was invented for
Use the Hayes command set:
The following commands are understood by virtually all modems supporting an AT command set, whether old or new.
D Dial
Dial the following number and then handshake
P
- Pulse DialT
- Touch Tone DialW
- Wait for the second dial toneR
- Reverse to answer-mode after dialing@
- Wait for up to 30 seconds for one or more ringbacks,
- Pause for the time specified in register S8 (usually 2 seconds);
- Remain in command mode after dialing.!
- Flash switch-hook (Hang up for a half second, as in transferring a call.)L
- Dial last number
See Linux Modem-HOWTO for details.
精彩评论