0

I know SO isn't the right place for theoretical questions, but rather for code exchange. Nevertheless, i can't find a complete solution so once again i'm putting my faith in SO community.

Problem:

As i worked with STM32 before i'm trying to replicate the UART interface. It's working well, but the questions arose.

It is possible to allow the ttyS# port to just ignore read() if the buffer file is empty?

Do i have to set it up by termios params or use Linux libs?

I had this problem, with STM32 ports, but it was solved via the interrupt interface in HAL libs. When it comes to Linux, i`m not sure.

I use:

fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd, F_SETFL, 0);
fcntl(fd, F_SETFL, O_NONBLOCK /* | O_ASYNC*/); //> doesn't suit well cause app reads its own data
Anton-Vas
  • 13
  • 3
  • Are you just asking how to do a nonblocking read? – user253751 Oct 14 '22 at 12:28
  • have your tried what is described in this Post: https://stackoverflow.com/questions/15119412/setting-serial-port-interruption-in-linux Regards Jan – airjabus Oct 14 '22 at 12:31
  • @airjabus, yes and it works almost perfect, but at random runs, the Linux port reads only its own msg-s. Therefore, i decided to ask more basic questions, thinking Barath Ravikumar and others were on the wrong path. – Anton-Vas Oct 14 '22 at 13:22
  • Your Linux program is not accessing a UART "*port*", but rather a serial terminal in a multitasking OS. Unless your program is properly constructed, nonblocking I/O is typically inefficient, adds read latency, and is to the detriment of all other processes. See https://stackoverflow.com/questions/25996171/linux-blocking-vs-non-blocking-serial-read/26006680#26006680 – sawdust Oct 14 '22 at 17:39
  • @sawdust, apologies for the inappropriate terminology. I know about inefficiency, but my goal is to make the UART interface capable of sudden external devices disconnection. Therefore, the stalling on read() is unacceptable (for simplicity i use only TX/RX/GND). I'm reading about C++ ports management, but there is a lot to learn). Thanks for the link. – Anton-Vas Oct 17 '22 at 08:12

0 Answers0