本人在mini2440 开发板下做个应用程序,想要通过串口来读GPS的数据,可是现在只能发送数据,而读不到串口的数据,不知道为什么?
有哪位大侠可以帮帮忙?这个问题困扰我很久了,感激不尽!!
下面是我的程序
struct termios gps_opt;
fd_gps = open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NONBLOCK); //打开串口1
if (fd_gps<0)
{
perror("open serial error!\n");
}
tcgetattr(fd_gps,&gps_opt); //初始化
bzero(&gps_opt, sizeof(gps_opt));
cfsetispeed(&gps_opt,B115200); //设置波特率 uartbiit[baud]
cfsetospeed(&gps_opt,B115200);
gps_opt.c_cflag |=(CLOCAL|CREAD);//忽略MODEM控制线,打开接受者
gps_opt.c_cflag &= ~CRTSCTS;
gps_opt.c_cflag &= ~CSIZE;
gps_opt.c_cflag |= CS8; //设置8数据位
gps_opt.c_cflag &= ~PARENB; //无奇偶校检
gps_opt.c_cflag &= ~CSTOPB;
//不是开发终端之类的,只是串口传输数据,而不需要串口来处理
gps_opt.c_oflag &= ~(OPOST); //选择原始数据输出
gps_opt.c_lflag &= ~(ICANON|ISIG|ECHO|ECHOE);//设置原始输入模式
//gprs_opt.c_iflag &= ~(INPCK|BRKINT|ICRNL|ISTRIP|IXON);
gps_opt.c_cc[VMIN] = 1; //指定了最少读取的字符数,如果设置为0,那么VTIME 就指定了读取每个字符的等待时间
gps_opt.c_cc[VTIME] = 0;
tcflush(fd_gps,TCIFLUSH);//刷新
if (tcsetattr(fd_gps,TCSANOW,&gps_opt) != 0) //装载初始化参数
{
perror("SetupSerial!\n");
close(fd_gps);
}
readgpstimer = new QTimer(this);
connect(readgpstimer,SIGNAL(timeout()),this,SLOT(readgpsCom()));
//关联定时器计满信号和相应的槽函数
readgpstimer->start(50);
//定时器开始计时,其中50表示50ms