1

I have a C program which works with a normal terminal using this code:

int dtr_rts = TIOCM_DTR | TIOCM_RTS; /* out-of-band signal */
...
int comfd = open(COM_PORT, O_RDWR);
...
ioctl(comfd, TIOCMBIS, &dtr_rts);

Now I need to run this program on a pseudo-terminal. How do I read DTR/RTS on master side? Is DTR/RTS set to 1 or to 0 by default (i.e., on open()) on /dev/pts/X?

Is TIOCMGET ioctl implemented for pseudo-terminals?

1

No, it's not. A pseudo terminal has no way to pass through serial ioctls like TIOCMBIS or TIOCSET.

See also:

Virtual tty client for network telnet/RFC2217 server?

Can terminal parameter changes on the slave side be detected on master?

Run a serial connection over SSH

  • I have found a workaround (although slight changes in the program which uses the tty are needed): Those processes are on the same computer (as using a pseudo-terminal implies), so I can use IPC mechanisms for out-of-band signalling. For example, I will create a file in slave and poll it in master after starting slave (this file must be removed before slave is started). [The program sets dtr_rts to 1 only once after it starts when it is ready to accept data.] – Igor Liferenko Aug 28 '19 at 9:13
  • You can also use a LD_PRELOAD hack to run unmodified programs, and pass the modem bits by re-purposing some unused termios special character (eg c_cc[VEOL2]), and passing the changes using the trick from the 2nd link. I'll add a full example when I have time and a machine where I can build & test. – mosvy Aug 28 '19 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.