无法在linux中打开串行端口
Unable to open serial port in linux
使用fedora 11,
串行类:
/*
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控制台[tty0]已启用serial8250:ttyS0在I/O 0x3f8(irq=4)是一个16550Aserial8250:ttyS1在I/O 0x2f8(irq=3)是一个16550A00:07:tttyS0在I/O 0x3f8(irq=4)处为16550A00:08:ttyS1在I/O 0x2f8(irq=3)处为16550A
在我的主程序中,我执行Ret=LS.Open(DEVICE_PORT,4800)
Ret值为-2,这意味着如上所述打开设备时出现错误可能是权限问题吗?我该如何解决这个问题并打开端口,谢谢!
可能是权限问题吗
很有可能。根据您使用的linux,有几个更改权限的选项。
这可能很简单,只需将当前用户添加到休假组即可。或者,您可能需要更改udev规则来设置串行端口的权限。
相关文章:
- Qt Q串行端口未编程设备未关闭
- 在 linux c++ 中没有通过串行端口发送的数据
- 检查串行端口Linux中是否有传入数据(cbInQue for linux)
- 使用 C++ 从 Linux 串行端口读取会提供混乱的数据
- usleep vs std::this_thread::sleep_for,当在 Linux 串行端口上写入/读取时
- 如何在Visual Studio中进行串行端口编程C++Windows和Linux之间的可移植性?
- 带有Linux的串行端口的PWM信号
- linux c++串行端口回显输出
- 从串行端口读取而不从缓冲区中删除(linux)
- Linux 串行端口读取 - 我可以更改输入缓冲区的大小吗?
- C、Linux 中的串行端口读取/打开错误
- 确定是否存在串行端口,Linux C/C++
- 在C++linux中将字符串写入串行端口
- 无法在linux中打开串行端口
- 在c++和Linux中,在有超时的情况下向串行端口写入和从串行端口读取数据
- Linux下c++中的串口.可以读和写串行端口同时发生
- 寻找linux串行端口的测试程序
- 在linux上,串行端口在第一对读写之后挂起
- Linux串行端口:输入中缺少数据
- 如何在Linux上使用polkit请求串行端口权限