免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2605 | 回复: 2
打印 上一主题 下一主题

[驱动] 请教Android系统一体机,用AT测试3G网卡为什么会发生回环? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-11-11 22:08 |只看该作者 |倒序浏览
本帖最后由 amos_ji 于 2010-11-12 10:30 编辑

请问各位高人,mips平台上Android系统的一体机,用AT测试3G网卡为什么会发生回环?如何消除?
现在是我发“AT\r”串口回“AT     OK    ”我想消除回环,请高手指教!代码如下:
int main(void)
{
int            fd;
struct termios options;

/* open the port */
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd, F_SETFL, 0);

/* get the current options */
tcgetattr(fd, &options);

cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);

options.c_cflag &= ~PARENB
options.c_cflag &= ~CSTOPB
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;

/* set raw input, 1 second timeout */
options.c_cflag     |= (CLOCAL | CREAD);
options.c_lflag     &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_oflag     &= ~OPOST;
options.c_cc[VMIN]  = 0;
options.c_cc[VTIME] = 10;
init_modem(fd);
/* set the options */
tcsetattr(fd, TCSANOW, &options);
close(fd);
}

int                  /* O - 0 = MODEM ok, -1 = MODEM bad */
init_modem(int fd)   /* I - Serial port file */
{
  char buffer[255];  /* Input buffer */
  char *bufptr;      /* Current char in buffer */
  int  nbytes;       /* Number of bytes read */
  int  tries;        /* Number of tries so far */

  for (tries = 0; tries < 3; tries ++)
  {
   /* send an AT command followed by a CR */
    if (write(fd, "AT\r", 3) < 3)
      continue;

   /* read characters into our string buffer until we get a CR or NL */
    bufptr = buffer;
    while ((nbytes = read(fd, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0)
    {
      bufptr += nbytes;
     // if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
      //  break;
    }

   /* nul terminate the string and see if we got an OK response */
    *bufptr = '\0';
   printf("\nread string is %s",buffer);
    if (strncmp(buffer, "OK", 2) == 0)
      return (0);
  }

  return (-1);
}

程序运行的结果如下:
read string is AT


OK

论坛徽章:
0
2 [报告]
发表于 2011-01-02 12:38 |只看该作者
应该解决了?哪里的问题呢?

论坛徽章:
0
3 [报告]
发表于 2011-01-03 13:45 |只看该作者
回环???
ate0 试试。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP