当前位置: 技术问答>linux和unix
急问!!!UART串口通信,可发送数据,不能接收数据
来源: 互联网 发布时间:2016-10-02
本文导语: 我从网上找到一个串口通讯的程序,自己改了一些设置。可是能发送数据,接收不到数据 #include #include #include #include #include #include #include #include #include /*uart_open_function*/ ...
我从网上找到一个串口通讯的程序,自己改了一些设置。可是能发送数据,接收不到数据
#include
#include
#include
#include
#include
#include
#include
#include
#include
/*uart_open_function*/
int open_port(int fd,int comport)
{
char *dev[]={"/dev/ttyS0","/dev/ttyS1","/dev/ttyS2"};
long vdisable;
if(comport==1)//uart1
{
fd=open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);
if(-1==fd){
perror("Can't Open Serial Port1!");
return(-1);
}
}
else if(comport==2)//uart2
{
fd=open("/dev/ttyS1",O_RDWR|O_NOCTTY|O_NDELAY);
if(-1==fd){
perror("Can't Open Serial Port2!");
return(-1);
}
}
else if(comport==3)//uart3
{
fd=open("/dev/ttyS2",O_RDWR|O_NOCTTY|O_NDELAY);
if(-1==fd){
perror("Can't Open Serial Port3!");
return(-1);
}
}
/*return uart status is block*/
if(fcntl(fd,F_SETFL,0)
#include
#include
#include
#include
#include
#include
#include
#include
#include
/*uart_open_function*/
int open_port(int fd,int comport)
{
char *dev[]={"/dev/ttyS0","/dev/ttyS1","/dev/ttyS2"};
long vdisable;
if(comport==1)//uart1
{
fd=open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);
if(-1==fd){
perror("Can't Open Serial Port1!");
return(-1);
}
}
else if(comport==2)//uart2
{
fd=open("/dev/ttyS1",O_RDWR|O_NOCTTY|O_NDELAY);
if(-1==fd){
perror("Can't Open Serial Port2!");
return(-1);
}
}
else if(comport==3)//uart3
{
fd=open("/dev/ttyS2",O_RDWR|O_NOCTTY|O_NDELAY);
if(-1==fd){
perror("Can't Open Serial Port3!");
return(-1);
}
}
/*return uart status is block*/
if(fcntl(fd,F_SETFL,0)