title: output of AT command c++ code
body: <p>I wrote the following code which sends a simple message to my mobile with GSM SM5100B. But it does not work. I would like to check the outputs of each printf line with c++ code. 
  For example</p>
  
  <pre><code>AT+CMFG=1
  ok
  AT+CMGS="69******"
  ok
  </code></pre>
  
  <p>etc.
  Is there any why to implement this?</p>
  
  <p>My code</p>
  
  <pre><code>#include &lt;stdio.h&gt; // standard input / output functions
  #include &lt;string.h&gt; // string function definitions
  #include &lt;unistd.h&gt; // UNIX standard function definitions
  #include &lt;fcntl.h&gt; // File control definitions
  #include &lt;errno.h&gt; // Error number definitions
  #include &lt;termios.h&gt; // POSIX terminal control definitionss
  #include &lt;time.h&gt;   // time calls
  
  int open_port(void)
  {
  int fd; // file description for the serial port
  fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
  if(fd == -1) // if open is unsucessful
  {
      printf("open_port: Unable to open /dev/ttyAMA0. \n");
  }
  else
  {
      fcntl(fd, F_SETFL, 0);
      printf("port is open.\n");
  }
  
  return(fd);
  } //open_port
  
  int configure_port(int fd)      // configure the port
  {
  struct termios port_settings;      // structure to store the port settings in
  
  cfsetispeed(&amp;port_settings, B9600);    // set baud rates
  cfsetospeed(&amp;port_settings, B9600);
  
  port_settings.c_cflag &amp;= ~PARENB;    // set no parity, stop bits, data bits
  port_settings.c_cflag &amp;= ~CSTOPB;
  port_settings.c_cflag &amp;= ~CSIZE;
  port_settings.c_cflag |= CS8;
  
  tcsetattr(fd, TCSANOW, &amp;port_settings);    // apply the settings to the port
  return(fd);
  
  }  
  
  void init_gsm()
  {
   printf("AT+CMGF=1\r\n");
   sleep(3);
   printf("AT+CMGS=\"+34603****\"\r\n");
   sleep(3);
   //printf("Hello\r\n%c",26); 
   printf("Hello\x1A");
   sleep(3);
  // printf("\x1A");
  
  }
  int main(void)
  {
  int fd = open_port();
  configure_port(fd);
  sleep(5);
  //query_modem(fd);
      init_gsm();
  return(0);
  
  }
  </code></pre>