LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-25-2008, 06:23 AM   #1
Simmo512
LQ Newbie
 
Registered: Nov 2007
Posts: 19

Rep: Reputation: 0
Smile 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
 
Old 10-25-2008, 06:46 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
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

Last edited by pinniped; 10-25-2008 at 06:47 AM.
 
Old 10-25-2008, 08:22 AM   #3
Simmo512
LQ Newbie
 
Registered: Nov 2007
Posts: 19

Original Poster
Rep: Reputation: 0
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....
 
Old 10-25-2008, 09:14 AM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
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.
 
Old 03-07-2009, 06:51 PM   #5
nenpa8lo
Member
 
Registered: Oct 2008
Location: Ireland
Distribution: Slackware 13.0, Slackware 13.37
Posts: 68
Blog Entries: 2

Rep: Reputation: 18
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
Next i open one terminal and type
Code:
stty -F /dev/ttyUSB1 raw clocal cs8 -cstopb -parenb ixon 115200
and in second i type
Code:
cat < /dev/ttyUSB1
When I power up the modem (which as default runs at 115200) i see the following
Code:
AT-Command Interpreter       ready
A
If i type
Code:
echo "AT" > /dev/ttyUSB1
i receive burst of 'T'
Code:
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT      TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT      TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT      TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT      TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT      TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Zoom Serial Port Modem jennirh9 Linux - Hardware 1 08-18-2004 01:06 AM
Serial port or Modem problems ugol Linux - Hardware 2 07-26-2003 03:37 PM
Finding serial port for my modem psyklops Linux - General 1 11-30-2002 09:12 AM
Which serial port modem to buy? R2RO Linux - General 5 08-08-2002 03:07 PM
Modem programming and serial port Drickx Linux - Networking 2 04-24-2002 10:24 AM


All times are GMT -5. The time now is 01:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration