# Ioctl like TIOCMIWAIT, or something that replaces it...



## ogogon (Nov 10, 2022)

Colleagues, tell me, please, is there in FreeBSD an ioctl similar to TIOCMIWAIT in SystemV?
How correctly, without a "stupid" poll in a cycle, to understand that the modem signals of the com port have changed?

I suppose that if TIOCMIWAIT, or some kind of its close analogue, is absent, then there is some other correct mechanism in the system?

Grateful for the answer,
Ogogon.


----------



## ralphbsz (Nov 10, 2022)

Think of the uses or a normal server operating system: what is it needed in normal operation? Say you are connecting a serial terminal (for logins), or you are connecting two computers to each other, for data exchange, for example via SLIP or PPP. Those are the common use cases for serial ports. If you enable hardware flow control, then those modem control signals (RTS/CTS) don't need to be monitored from the user process, nor manually set. If you disable hardware flow control, then those signals are irrelevant. Similarly, if you set modem control, then DCD/DSR/... are automatic, otherwise irrelevant.

What I'm saying: The functionality of manually checking and setting the modem control signals is not commonly needed; for the rare case that needs them, a synchronous call is sufficient. The use case you want (which is to build a hardware monitoring device) is not what the serial stack is intended for. I fully believe that Linux has it, but that's because Linux has a wider spectrum of use cases which is outside the normal server computing model, for example laboratory data acquisition.

Another remark: Don't be so dismissive of polling. What time resolution do you need? It would be hard to argue that you need anything better than 10ms. So try putting the ioctl for checking the modem control signals (I think it is TIOCMGET, but that's from memory) in a loop that is executed every 100 times a second, and measure the CPU consumption. My educated guess is that polling is a perfectly adequate technique here. For example: At home, I poll two pressure sensors that are connected via serial ports. Reading their value requires an interestingly complex serial protocol (I use ModBus), and I do that 20 times per second. To make matters worse, the whole code is written in Python. It uses 3-4% of the CPU. In efficient C, it would probably be an order of magnitude faster.


----------



## ogogon (Nov 12, 2022)

Thanks for the answer, but it's kind of sad...

It turns out that you need to write two methods for obtaining information and adjust the C preprocessor so that the corresponding one is compiled on each platform.
Or do only a polling loop with a time delay and get ridiculed by linuxoids who start saying that BSD programmers live like bears in a den...


----------



## ralphbsz (Nov 12, 2022)

It's not kind of sad, it is the way engineering goes. Every product or project is a compromise. FreeBSD is a compromise, to be a really good, clean, stable, and streamlined server OS. It can also do desktop, but that's up to the user to configure. It is not used much for hardware hacking, or as a base for hardware-close embedded systems.

Use the appropriate tool. If you want to check modem control lines and not write a polling loop, Linux (or an embedded OS or writing kernel code yourself) is the correct answer. You are bemoaning that a philips screwdriver is not very good at putting in nails: I agree. Don't use it if it doesn't fit.

I have several Raspberry Pi around the house, one of them in continuous production. I tried FreeBSD on it, and switched to Linux (Raspbian = Debian). Not because I like it particularly, but because the hardware support was just much better. Certainly, FreeBSD is "Turing complete", and could have done what I wanted with sufficient effort. But I used the path of using the appropriate tool.


----------

