linux 串口应用开发,该怎么解决

linux 串口应用开发
这个是linux串口的一个应用程序
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "errno.h"
#include "linux/termios.h"
#define dev "/dev/ttyS0"
#define BUFF_SIZE 512
int main()
{
int stty_fd,n;
char buffer[BUFF_SIZE];
struct termios opt;
stty_fd=open(dev,O_RDWR);
if(stty_fd<0)
{
printf("open serial error!\n");
return 0;
}
else
{
printf("open serial sucess!\n");
}
tcgetattr(stty_fd,&opt);
tcflush(stty_fd,TCIOFLUSH);
//set baud
cfsetispeed(&opt,B115200);
cfsetospeed(&opt,B115200);
//set data
opt.c_cflag &=~CSIZE;
opt.c_cflag |=CS8;

opt.c_cflag &=~PARENB;
opt.c_iflag &=~INPCK;

opt.c_cflag &=~CSTOPB;

opt.c_cc[VTIME]=150;
opt.c_cc[VMIN] =0;
//把配置写入设备
if(0!=tcsetattr(stty_fd,TCSANOW,&opt))
{
printf("set error!\n");
return 1;
}
tcflush(stty_fd,TCIOFLUSH);
while(1)
{
n=read(stty_fd,buffer,BUFF_SIZE);
if(n<0)
{
printf("read error!\n");
break;
}
buffer[n]='\0';
printf("%s\n",buffer);
if(0==strncmp(buffer,"quit",4))
{
printf("user send quit!\n");
break;
}
}
printf("program will exit!\n");
close(stty_fd);
}
编译这个程序没有问题,现在我在第一个控制台上运行它,然后在第二个控制台上输入命令
echo serial > /dev/ttyS0 但是在第一个控制台上却没有输出serial,可是我在第二个控制台
上已经把serial写到ttyS0了。求指点

------解决方案--------------------
不用程序,一边cat 一边echo看行不行
------解决方案--------------------
哦不对,收发不能这么环回来的
------解决方案--------------------
下个SCT(linux串口测试程序)源码,编译测试。