I'm trying to configure my serial port (/dev/ttyS0) to automatically control RTS pin. I already can do it from user space by ioctl TIOCM_RTS flag toggling but it's too slow in my case - slave device respond too fast and I miss it.
I tried to achieve it by enabling RS485 mode but I end with bellow error:
unable to set IOCTL:: Inappropriate ioctl for device
My implementation
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 output:
[ 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
How can I force my serial port to work in this mode or maybe there is another way to achieve RTS automatic control?
OS:
4.15.0-23-generic #25-Ubuntu SMP Wed May 23 18:02:16 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux