title: Why my AT command echo in my GSM modem?
body: <p>I have a GSM modem and test it by putty. it works. Then I send AT with my c++ program, but modem replies AT. It just echoes my command and no answer OK.<br>
  this is my code :  </p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;termios.h&gt;
  #include &lt;iostream&gt;
  int fd;
  int openport(void)
  {
  
  fd=open("/dev/ttyUSB0",O_RDWR|O_NOCTTY|O_NDELAY);
  
          if (fd==-1)
                  {
                  perror("open_port: unable to open port /dev/ttyUSB0\n");
                  return -1;
                  }
          else
                  {
                  printf("open_port: succesfully open port /dev/ttyUSB0\n");
                  fcntl(fd,F_SETFL,0);
                  return 1;
                  }
  }
  void closeport(void)
  {
      close(fd);
  }
  void configport(void)
  {
  struct termios options;
  tcgetattr(fd,&amp;options);
  cfsetispeed(&amp;options,B9600);
  cfsetospeed(&amp;options,B9600);
  options.c_cflag |=  (CLOCAL | CREAD);
  tcsetattr(fd,TCSANOW,&amp;options);
  options.c_cflag &amp;= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &amp;= ~ PARENB;
  options.c_cflag &amp;= ~CSTOPB;
  options.c_cflag &amp;= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_iflag &amp;= ~(IXON|IXOFF|IXANY);
  }
  void writeport1(void)
  {
      char w[]="AT\r\n";
  
      //std::cout &lt;&lt; strlen(w);
      //std::cout &lt;&lt; w;
  
      write(fd,w,sizeof(w));
  }
  
  
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
      int aa ;
      char i[10];
      aa=openport();
      if (aa==1)
      {
          configport();
          writeport1();
          printf("start reading ..... \n");
          aa=read(fd,i,sizeof(i));
          i[aa]=0;//terminate the string
          //std::cout &lt;&lt; i &lt;&lt; std::endl;
          printf("finish reading ..... \n");
  
      }
  
      closeport();
      return a.exec();
  }
  </code></pre>
  
  <p>the output is this :   </p>
  
  <blockquote>
    <p>Go to open port open_port:<br>
    succesfully open port /dev/ttyUSB0 port<br>
    [root@FriendlyARM /]#./SerialPort -qws<br>
    open_port: succesfully open port /dev/ttyUSB0<br>
    start reading .....</p>
  </blockquote>
  
  <p>where is my mistake?</p>