我正在尝试配置串行端口(/ 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