1

I'm writing software to communicate with badly designed hardware. This hardware can communicate with linux pc (kernel 4.15) by RS485 line (9600 8N1) and it has very short timings: pc should reply in 2ms after receiving request from device.

I was able to solve this task using LOW_LATENCY flag and /sys/class/tty/ttySx/rx_trig_bytes file.

After opening port "rx_trig_bytes" file contents changes to "14", so I need write "1" to it after opening port to get good reply latency.

Is there any way to make this by API call or fix it after system boot / driver load ? Current realization looks ugly :(

Alexandr Shutko
  • 1,857
  • 2
  • 20
  • 27
  • And what happens when you write "1" to the file /sys/class/tty/ttySx/rx_trig_bytes in your code? – user253751 Jun 14 '19 at 03:03
  • After writing "1" delay between receive and send became submillisecond. "1" mean generate interrupt when one or more bytes are in uart rx fifo. So "14" - generate interrupt when 14 or more bytes received from uart and placed to fifo. – Alexandr Shutko Jun 14 '19 at 03:33
  • So are you asking how to write 1 to the file? – user253751 Jun 14 '19 at 04:07
  • No. Look. I use open("/dev/ttyS2") then ioctl(fd, TIOCGSERIAL...) then tcgetattr()/cfsetospeed()/cfsetispeed()/tcsetattr()/tcflush and then I open file at /sys/ and write "1" there. This is ugly so I want to known is there any way to control rxfifo using API ? Or may be this "1" can be set as default value for port during system boot ? – Alexandr Shutko Jun 14 '19 at 04:18
  • The API ***is*** the file in /sys. – user253751 Jun 14 '19 at 04:33

1 Answers1

1

Funny you find this way ugly, considering everything is a file in Unix, it should be the smart way.

I guess you are entitled to your own aesthetic sense.

If you want to make another buffer size the default you can always change it in the driver and recompile the kernel as suggested here.

Marcos G.
  • 3,371
  • 2
  • 8
  • 16
  • Well. I'm working with single file /dev/ttyS2 and all its parameters was set using its fd and ioctl/tcsetattr/etc.Now I need open another file to setup this file. I don't think this is not normal :( but it looks like this is best way. Thanks for answer. – Alexandr Shutko Jun 14 '19 at 05:07
  • You're welcome. I think the advantage of recompiling is you would not need to change anything on user space whereas writing the file requires root. If this is a one off thing in one machine I guess it's worthwhile to recompile... – Marcos G. Jun 14 '19 at 05:10