Linux串口打不开,无法在Linux打开串口

使用的Fedora 11,无法在Linux打开串口

在串行类:

/*

\return 1 success

\return -1 device not found

\return -2 error while opening the device

\return -3 error while getting port parameters

\return -4 Speed (Bauds) not recognized

\return -5 error while writing port parameters

\return -6 error while writing timeout parameters

*/

`char serialib::Open(const char *Device,const unsigned int Bauds){`

struct termios options; // Structure with the device's options

// Open device

fd = open(Device, O_RDWR | O_NOCTTY | O_NDELAY); // Open port

if (fd == -1) return -2; // If the device is not open, return -1

fcntl(fd, F_SETFL, FNDELAY); // Open the device in nonblocking mode

..................... 。

[termina]$ dmesg | grep tty

console [tty0] enabled

serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A

serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A

00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A

00:08: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A

.......................................... .............

在我的主程序中,我做了Ret = LS.Open(DEVICE_PORT,4800);

和Ret值是-2这意味着如上所述打开设备时出现错误 它可能是一个权限问题?我该如何解决这个问题,并打开端口,谢谢!

+4

“可能”?你的意思是你没有检查'errno'? –

2012-02-10 05:42:26

+0

这就是我想知道的,不是在那里显示的错误 –

2012-02-10 06:04:38

+2

当'open'返回'-1'时,而不是仅仅返回,添加一行来打印实际的错误。这可以通过['perror'](http://linux.die.net/man/3/perror)函数完成。如果您不明白错误消息,请编辑您的问题以包含它。 –

2012-02-10 06:30:31

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值