Hello,
I’m working with embedded linux (kernel 4.19).
I am working on dynamic UART changing mode rs485/rs232 with a tranceiver that permit the both possibility of transmissions. Actually, I do that changing mode with a c script using ioctl to drive CTS,RTS signals. It works fine, but to “securize” the process, I would like to enable the changing mode only if UART is not already use by an other script.
for exemple, let’s take uart0: “/dev/ttyuart0” that have got RTS and CTS.
so, when i want to transmit data, I use a c script with serial librarie and the data is transmitted during 2 minutes. During this time, I change successively the mode of data transmission (rs485<->rs232). The change of mode works fine (I verified signals with my oscilloscope), but data seems to don’t be transferred all the time. So I would like something to “lock” the uart if a process using it (when the file is open to push data), and release it after data transmission or close of “/dev/ttyuart0”.
I have already tested many things: monitoring by using linux “inotify”. The monitoring works fine and I succes to catch the events when a serial console like minicom open “/dev/ttyuart0” for example. But, the second part tat consist to lock the uart is a bit difficult. I try to use lockf function, but it does not work.
If you get any idea to do something like that, or a best idea, I’ll take it to investigate.
Thanks by advance, best reguards.