# Endless data loop from dev/ttyUSB while sending AT commands

## tester777

I have problem sending AT commands to my USB modem.

At first I tried php-serial class, but when i was reading data, I got endless loop with strange data. Then I tried to debug problem and opened putty terminal, made command

```
    cat /dev/ttyUSB0
```

and then sent command `echo "AT" > /dev/ttyUSB0` after that I always got never ending loop from `cat /dev/ttyUSB0` like this:

```
    AT

    AT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^
```

and this loop never ends. On windows all works just fine. I can connect to USB modem via virtual COM port and send command / get answer.

Question is why cant I just receive "OK" message from console, but instead of this I got this data loop?

Tried different huawei USB modems, and different stty settings and also default settings for huawei modems:

```
    Baud rate: 9600 / 115200

    Parity: none

    Data bits = 8

    Stop bits = 1

    Flow control = none

    test dev # uname -a

    Linux test 3.5.7-gentoo #3 SMP Sun Feb 17 04:58:22 EET 2013 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ AuthenticAMD GNU/Linux
```

**EDIT:**

compiled newer kernel: 3.6.11-gentoo and now when sending command:

```
    echo "AT" > /dev/ttyUSB0
```

got result like:

```

    OK

    AT

    OK

    AT

    OK

    AT
```

it never ended, I terminated cat command, then sent other ( make call command ):

```
    echo "ATDT 27789388;" > /dev/ttyUSB0
```

and got answer from cat without loop.

```

    systest ~ # cat /dev/ttyUSB0

    ATDT 27789388;

    OK
```

so why tty terminal is acting so strange ? maybe I don't know something about sending/reading data on serial ports ?

----------

## Ant P.

Try sending a carriage return (\r) instead - echo adds a newline (\n) by default.

----------

## tester777

 *Ant P. wrote:*   

> Try sending a carriage return (\r) instead - echo adds a newline (\n) by default.

 

Can you write how exactly i need to send command ?

----------

## NeddySeagoon

tester777,

```
emerge minicom
```

There is no need to mess with cat and echo

----------

## tester777

 *NeddySeagoon wrote:*   

> tester777,
> 
> ```
> emerge minicom
> ```
> ...

 

Thanks for that tip, I will read docs of that soft, but I was writing php application and used php-serial class for modem communication, but that class returned same thing - never ending loop. So i started debugging, and found that it's not php problem, but linux.

----------

## NeddySeagoon

tester777,

Its not a linux problem.  It has to do with the way you set up and talk to the serial port.

minicom has worked since before I began with linux in 1999.

Its open source software, so you can see what it does.

You can also try the chat program, which is used to establish a serial connection to a remote system before PPP is started.

It operates from a script.

I suspect cat and echo do not give the result you want because they are both trying to control the serial port at the same time.

Two drivers for the same hardware is always a bad thing.

----------

## tester777

 *NeddySeagoon wrote:*   

> tester777,
> 
> Its not a linux problem.  It has to do with the way you set up and talk to the serial port.
> 
> minicom has worked since before I began with linux in 1999.
> ...

 

I installed minicom, and started reading docs, but looks like it is like text client, and dialing and other stuff is made manually by user navigating text menu.

I need to send some commands to modem, so it could send SMS or make call or conference call using AT commands.

I wanted to do that over php, that would open stream and paste data into serial port, and then after some time tried to read answer from that port.

Can minicom be used like this ?

----------

## NeddySeagoon

tester777,

minicom is intended to be used interactively by it can store AT command strings too.

To semi-automate what you want, chat is probably better, since it sends AT commands as you script and can listen or responses and deal with some error conditions.

By all means use php but only after you know the process you want to write in php works when you do it at a lower level.

e.g, with minicom and chat.  chat is provided by net-dialup/ppp

----------

## tester777

 *NeddySeagoon wrote:*   

> tester777,
> 
> minicom is intended to be used interactively by it can store AT command strings too.
> 
> To semi-automate what you want, chat is probably better, since it sends AT commands as you script and can listen or responses and deal with some error conditions.
> ...

 

Thanks for advice, you pointed me to right way and i found net-misc/ckermit, looks like kermit does what i need and i also will read docs about chat app.

----------

## NeddySeagoon

tester777,

Kermit provides lots of protocols for moving data over a serial link.

The most important thing to know about Kermit is that it really was named after a certain Green Frog :)

----------

