【求助】读串口时没反应(有程序)
时间:2005-05-25
来源:互联网
我现在在做ARM S3C4510B的嵌入式开发,写了个读串口的程序,但是一用到read(fd,buff,1)程序就没反应了,连之前的printf都没反应,把此句注释掉后所有printf都能输出。我是用虚拟机vmare里的linux的,是程序原因还是我的虚拟机不支持穿口啊???请大虾们多多帮助。
主体程序如下://#####################gps.c############################
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<stdlib.h>
#include<termios.h>
#include<fcntl.h>
int status;
char ca[8],tmp;
int quart(int fp);
main()
{
int fp;
int max=80;
int i;
unsigned char wd,jd,Data[512];
unsigned char Time[32],PositionX[32],PositionY[32],Date[32];
unsigned char cc[32];
struct termios opt;
fp=open("/dev/ttyS0",O_RDWR);//以读写方式打开串口1
//设置串口:波特率19200,8位数据位,奇校验、1位停止位
tcgetattr(fp,&opt);
tcflush(fp,TCIOFLUSH);
cfsetispeed(&opt,B19200);
cfsetospeed(&opt,B19200);
opt.c_iflag=1;
opt.c_oflag=0;
opt.c_cflag=3261;
opt.c_lflag=0;
opt.c_line=' ';
tcsetattr(fp,TCSANOW,&opt);
tcflush(fp,TCIOFLUSH);
printf("please wait");
while(!quart(fp)) ; //等待帧标志:
for(i=0;i<max;i++)
{read(fp,cc,1);
Data=cc[0];
printf("%c",Data);}
}
int quart(int fp) //fp是IO口句柄,如果收到标志,返回1,否则0;
{ status=0;
read(fp,ca,1);
tmp=ca[0];
if(tmp=='$') //帧头,SectionID为逗号计数器/
status=1;
return status;
}
主体程序如下://#####################gps.c############################
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<stdlib.h>
#include<termios.h>
#include<fcntl.h>
int status;
char ca[8],tmp;
int quart(int fp);
main()
{
int fp;
int max=80;
int i;
unsigned char wd,jd,Data[512];
unsigned char Time[32],PositionX[32],PositionY[32],Date[32];
unsigned char cc[32];
struct termios opt;
fp=open("/dev/ttyS0",O_RDWR);//以读写方式打开串口1
//设置串口:波特率19200,8位数据位,奇校验、1位停止位
tcgetattr(fp,&opt);
tcflush(fp,TCIOFLUSH);
cfsetispeed(&opt,B19200);
cfsetospeed(&opt,B19200);
opt.c_iflag=1;
opt.c_oflag=0;
opt.c_cflag=3261;
opt.c_lflag=0;
opt.c_line=' ';
tcsetattr(fp,TCSANOW,&opt);
tcflush(fp,TCIOFLUSH);
printf("please wait");
while(!quart(fp)) ; //等待帧标志:
for(i=0;i<max;i++)
{read(fp,cc,1);
Data=cc[0];
printf("%c",Data);}
}
int quart(int fp) //fp是IO口句柄,如果收到标志,返回1,否则0;
{ status=0;
read(fp,ca,1);
tmp=ca[0];
if(tmp=='$') //帧头,SectionID为逗号计数器/
status=1;
return status;
}
作者: 小样82 发布时间: 2005-05-25
应该是虚拟机的原因。运行read(fd,buf,1)导致前面的输出都没有了是因为你前面的输出没有“\n”回车换行,前面的字符在缓冲区中来不及打印。
作者: 风雪狂客 发布时间: 2005-06-03
如何设置串口全双工方式工作呢?输入和输出使用同一个缓冲区吗?
作者: newabc 发布时间: 2005-11-03
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28