当前位置: 技术问答>linux和unix
串口通信 有时得到正确的值,有时又接收不到,为什么?谢了!!!
来源: 互联网 发布时间:2016-06-24
本文导语: 求助各位高手!! 我现在在写一个串口程序,程序如下: #include #include #include #include #include #include #include #include #include /*uart_open_function*/ int open_port(int fd,...
求助各位高手!!
我现在在写一个串口程序,程序如下:
#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);
printf("ttyS0 n");
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);
printf("ttyS1 n");
if(-1==fd){
perror("Can't Open Serial Port2!");
return(-1);
}
}
else if(comport==3)//uart3
{
fd=open("/dev/ttyS2",O_RDWR|O_NOCTTY);
printf("ttyS2 n");
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);
printf("ttyS0 n");
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);
printf("ttyS1 n");
if(-1==fd){
perror("Can't Open Serial Port2!");
return(-1);
}
}
else if(comport==3)//uart3
{
fd=open("/dev/ttyS2",O_RDWR|O_NOCTTY);
printf("ttyS2 n");
if(-1==fd){
perror("Can't Open Serial Port3!");
return(-1);
}
}
/*return uart status is block*/
if(fcntl(fd,F_SETFL,0)
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!