|
|
不知道这个问题贴在这里是否合适
程序代码如下(从网上找的)
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <termios.h>
#define BAUDRATE B115200
#define MODEDEVICE "/dev/ttyS0"
int main()
{
int fd,c=0,res;
struct termios oldtio,newtio;
char buf[256];
printf("start...\n");
fd=open(MODEDEVICE,O_RDWR);
if (fd<0)
{
perror(MODEDEVICE);
exit(1);
}
printf("open...\n");
tcgetattr(fd,&oldtio);
bzero(&newtio,sizeof(newtio));
newtio.c_cflag=BAUDRATE |CS8|CLOCAL|CREAD;
newtio.c_iflag=IGNPAR;
newtio.c_oflag=~OPOST;
newtio.c_lflag &=~(ICANON|ECHO|ECHOE|ISIG);
tcflush(fd,TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
printf("reading...\n");
while(1)
{
res=read(fd,buf,255);
buf[res]=0;
printf("res=%d vuf=%s \n",res,buf);
sleep(5);
if (buf[0]=='@') break;
}
printf("clos...\n");
close(fd);
tcsetattr(fd,TCSANOW,&oldtio);
return 0;
}
在debian下编译通过,可就是接收不到数据,各位看看那里的问题
我的手持机没有问题。 |
|