首页 > 解决方案 > Linux UART (16550A) RS485 模式

问题描述

我正在尝试将我的串行端口 (/dev/ttyS0) 配置为自动控制 RTS 引脚。我已经可以通过 ioctl TIOCM_RTS 标志切换从用户空间执行此操作,但在我的情况下它太慢了 - 从设备响应太快,我错过了它。

我试图通过启用 RS485 模式来实现它,但我以以下错误结束:

    unable to set IOCTL:: Inappropriate ioctl for device

我的实现

  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:");

}

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

如何强制我的串口工作在这种模式下或者可能有另一种方法来实现 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

标签: linuxserial-portuartflow-controlrs485

解决方案


推荐阅读