KPR*_*KPR 5 linux serial-port flow-control rs485 uart
我正在尝试配置我的串行端口(/dev/ttyS0)以自动控制 RTS 引脚。我已经可以通过 ioctl TIOCM_RTS 标志切换从用户空间执行此操作,但在我的情况下它太慢 - 从设备响应太快,我错过了它。
我尝试通过启用 RS485 模式来实现它,但最终出现以下错误:
unable to set IOCTL:: Inappropriate ioctl for device
Run Code Online (Sandbox Code Playgroud)
我的实现
port_fd = open(port.c_str(), O_RDWR);
if (port_fd != -1) {
struct serial_rs485 rs485conf={0};
rs485conf.flags |= SER_RS485_ENABLED;
rs485conf.flags |= SER_RS485_RTS_ON_SEND;
rs485conf.delay_rts_before_send = 0;
int rv = ioctl(port_fd,TIOCSRS485, &rs485conf);
if(rv){
printf("rv = %d\n", rv);
perror("unable to set IOCTL:");
}
Run Code Online (Sandbox Code Playgroud)
dmesq 输出:
[ 0.000000] console [tty0] enabled
[ 1.338716] 00:01: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[ 1.359441] 00:02: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[ 1.380168] 00:03: ttyS2 at I/O 0x3e8 (irq = 7, base_baud = 115200) is a 16550A
[ 1.400953] 00:04: ttyS3 at I/O 0x2e8 (irq = 7, base_baud = 115200) is a 16550A
[ 1.421677] 00:05: ttyS4 at I/O 0x2f0 (irq = 7, base_baud = 115200) is a 16550A
[ 1.442338] 00:06: ttyS5 at I/O 0x2e0 (irq = 7, base_baud = 115200) is a 16550A
Run Code Online (Sandbox Code Playgroud)
我怎样才能强制我的串口工作在这种模式下,或者也许有另一种方法来实现RTS自动控制?
操作系统:
4.15.0-23-generic #25-Ubuntu SMP Wed May 23 18:02:16 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1279 次 |
| 最近记录: |