|
Jangel 发表于 2013-5-31 08:49
你要贴你的代码出来,拒绝玩猜谜游戏哦
fd = open("/dev/ttySAC1", O_RDWR);
if(fd!=-1)
serial_open_flag=1;
else
perror("Can not open Serial_Port \n!");
memset(&opt, 0, sizeof opt);
tcgetattr(fd, &opt);
tcflush(fd, TCIOFLUSH);
cfsetispeed(&opt,B9600);
cfsetospeed(&opt,B9600);
status = tcsetattr(fd, TCSANOW, &opt);
if(status != 0)
{
perror("tcsetattr fd1");
}
tcflush(fd, TCIOFLUSH);
tcgetattr(fd, &opt);
opt.c_cflag &= ~CSIZE;
opt.c_cflag |=CS8;
opt.c_cflag &= ~PARENB;
opt.c_iflag &= ~INPCK;
opt.c_cflag &= ~CSTOPB;
opt.c_cc[VTIME] = 30;
opt.c_cc[VMIN] = 0;
tcflush(fd, TCIFLUSH);
if (tcsetattr(fd, TCSANOW, &opt) != 0) {
perror("SetupSerial 3");
}
while(1)
{
write(fd,serial_ouput_A1_S1,2);// 串口发送2个字符的数据
read(fd,buff,8);//串口读取8个字节的数据
}//另外的实验板是收到2个字节的数据,则实验板回传8个字节的数据回来
代码是按照板子给的例程自己写的,麻烦版主看下是哪个地方有问题.如果未先用QT文件系统自带的串口程序配置ttySAC1,程序就只能成功运行到发送数据处,读取的时候就一直暂停,而在利用QT文件系统自带的串口测试程序将波特率为9600,点击确定后,再运行我写的串口程序时该Qt程序能正常工作,请问这个问题该怎么解决? |
|