Modem serial port help needed
Hi,
CentOS 5 2.6.18-8.1.15.el5xen I need to send my modem some AT commands and capture the output from within a script. I can do what I need with minicom manually but have no idea how to take this to a script. I don't need to make a connection to an ISP or receive an inbound connection, I just need to issue certain AT commands like the following:- AT+CMGF=1 My modem requires /dev/ttyUSB0, 8N1, HW No, SW Yes I've found a few folks in the past talking about using send/receive which I'm familiar with, but I can't see how I can drive a terminal menu program like minicom with them. I've tried simply doing an 'echo at > /dev/ttyUSB0' but nothing happens. My guess is that I need to configure my serial port first somewhere and then some how do the initialise modem bit that minicom does? Can someone please point this relative newbie in the right direction please, maybe with an example script? Thanks in advance Simmo |
To set serial port parameters, use 'stty' - for example:
stty -F /dev/ttyUSB0 raw clocal cs8 -cstopb -parenb ixon raw = set all sorts of bits (some of which we override later) clocal = don't use Modem hardware control lines cs8 = 8-bit data -cstopb = 1 stop bit -parenb = no parity bit ixon = use xon/xoff (software flow control, aka 'software handshake') You can still send commands to the modem using 'echo' - I usually use something like: echo -e -n "whatever\n" I use "-e -n" so I have more control over what I can send - for example, when quickly testing intelligent sensors, I can control whether I send \r\n or just \r or \n at the end of a line. ("intelligent" sensors aren't really all that intelligent and some are easily confused) With "-e -n" I can also send binary data to, say, set up my GPS. A more flexible means of chatting with the modem is the "chat" program, which should have been installed if you installed ppp. man chat |
Thanks for the prompt reply, I'm afraid I've got no further though ...
I've used # stty -F /dev/ttyUSB0 raw clocal cs8 -cstopb -parenb ixon then tried both # echo -e -n "AT\n" and # chat -v '' ATZ OK AT '' but I don't get any response from the modem. Looking at the minicom terminal screen it states on its status line that its offline but using 115200 8N1 which I have set in the configuration file, do you think it might be the serial port speed thats missing? If so how would I specify this with stty? I'm also unsure what minicom does when its in it "initializing" phaze.... |
Usually the speed doesn't matter on a USB serial modem device (unless it's a USB-to-serial converter). To set the speed with stty, just include the speed in the configuration line - for example:
stty -F /dev/ttyUSB0 raw 115200 When minicom is "initializing" it sets the serial port parameters then sends the modem initialization string (ATZ + others). You can't (at least not sensibly) check the modem response when using the "echo" command to send data to the modem. Either use minicom or set up 'chat' to log the session. Are you sure you're issuing AT commands on the correct interface? Some modems use ttyUSB1 or ttyUSB2 for the AT command set and ttyUSB0 for ppp traffic only. |
I have something similar. I use KEYSPAN USA-19HS to communicate with GSM modem by using AT commands. After lsusb | grep Keyspan i get:
Code:
Bus 006 Device 003: ID 06cd:0121 Keyspan USA-19hs serial adapter Code:
stty -F /dev/ttyUSB1 raw clocal cs8 -cstopb -parenb ixon 115200 Code:
cat < /dev/ttyUSB1 Code:
AT-Command Interpreter ready Code:
echo "AT" > /dev/ttyUSB1 Code:
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT |
All times are GMT -5. The time now is 07:11 PM. |