3

I have a remote serial device attached to /dev/ttyAMA0 that requires a serial command to be issued before a program connects so that the program will read the return string and automatically recognize it. I can not change the behavior of the main program.

Is there any way to run a script when a userland program accesses a /dev/tty character device?

Adding a udev rule only runs during boot and not, say when I connect with minicom.

I was researching a way to make a fake character device that would do this but it was looking like I would need to write a device driver.

3
  • You need to more clearly explain what "access" is. Because there's a significant difference between a program on the machine opening a terminal device, and an external terminal (emulator) connecting to a serial device.
    – JdeBP
    Mar 10, 2017 at 20:18
  • @JdeBP, updated the question
    – uMinded
    Mar 10, 2017 at 20:37
  • I don't completely understand who needs to issue a "serial command" to what, but would a program help that pipes between /dev/ttyAMA0 and another pseudo tty, and does whatever initialization is required first? Then the userland program can access the pseudo tty slave instead of /dev/ttyAMA0. It's not hard to write such a program, look at openpty.
    – dirkt
    Mar 11, 2017 at 17:18

1 Answer 1

0

I ended up monitoring the log file and triggering the even when it wanted to connect.

tail -f /tmp/lw.stdout.log | grep -q --line-buffered "INFO: Connecting to USB,/dev/ttyAMA0" && echo -n $'\cx' > /dev/ttyAMA0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .