控制GPRS模块的串口程序解决思路

控制GPRS模块的串口程序
大家好,我想利用程序来控制GPRS模块,也就是通过程序来发送AT指令以及接受
但是我的程序只发送了一个简单的“AT”,确不能读到回应,想请教一下大家。
通过minicom或者sscom发送AT指令,GPRS模块都能正确的回应,所以应该是程序问题。
但是通过minicom或者sscom调试程序,接受和发送都与我预想的一致,很困惑。
附上出错信息:
Serial Port Speed:115200bps
/*************************/
now 4 bytes has been written to the serial port
Reading timeout
以下是程序清单:
#include <sys/types.h>  
#include <sys/stat.h>  
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/select.h>
#include <stdio.h>  
#include <string.h>
#include <stdlib.h>  
#include <unistd.h>  

#include <fcntl.h>  
#include <termios.h>  
#include <errno.h>  

 
typedef 
enum 
{
  SERIAL_8N1=0,
  SERIAL_7E1=1,
  SERIAL_7O1=2,
  SERIAL_7S1=3
}serial_format;
const char * serial_port[]={
  "/dev/ttyS0",
  "/dev/ttyS1",
  "/dev/ttyS2",
  "/dev/ttyS3",
  "/dev/ttyS4",
"/dev/ttyUSB0"
};
int serial_open(int port)
{
  int fd = open(serial_port[port], O_RDWR);//|O_NONBLOCK);  
  if (-1 == fd)  
  {  
  perror("Can't Open Serial Port");
  exit (-1);  
  }  
  else 
  {
  fcntl(fd, F_SETFL, 0);
  }
  return fd;
}

 
void serial_format_set(int fd,serial_format format)
{
  int status=0;
  struct termios options; 
  if ( tcgetattr( fd,&options) != 0) 
  { 
  perror("serial fomat abnormal");  
  exit (-1);
  }
  options.c_cflag &= ~CSIZE; 
  switch (format)
  {  
  case SERIAL_8N1:
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_iflag &= ~(INPCK | ISTRIP);
  break;  
  case SERIAL_7E1:  
  options.c_cflag |= PARENB;
  options.c_cflag &= ~PARODD;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS7;
  options.c_iflag |= (INPCK | ISTRIP);

  break;
  case SERIAL_7O1:
  options.c_cflag |= PARENB;
  options.c_cflag |= PARODD;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS7;
  options.c_iflag |= (INPCK | ISTRIP);

  break;
  case SERIAL_7S1:
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_iflag &= ~INPCK;
  options.c_iflag|=ISTRIP;
  break;
  default:  
  perror("serial format abnormal");
  exit (-1);
  } 
  tcflush(fd,TCIOFLUSH); 
  status=tcsetattr(fd, TCSANOW, &options);
  if (status != 0)