Reputation: 1081
Is there a way to duplicate a serial device /dev/ttyUSB0 on Linux (Ubuntu 14.04) ?
I made a program which read the data from the RS232 port and I would like to execute two instances of my program with different options in parallel. However, I cannot open the /dev/ttyUSB0 twice from my program (writen in C).
Ideally, I would like the ttyUSB0 driver to create two identical devices. (/dev/ttyUSB0 and /dev/ttyUSB1). The driver would make sure that ttyUSB1 is an exact copy of ttyUSB0.
Is there a way to perform this from the command line (bash) or should I make my own special serial port driver ?
Upvotes: 2
Views: 4013
Reputation: 531490
You can use tee
to output anything written to /dev/ttyUSB0
to two named pipes.
mkfifo copy1 copy2
tee copy1 copy2 < /dev/ttyUSB0 > /dev/null &
program1 < copy1
program2 < copy2
(Strictly speaking, you only need one named pipe; the other program could read from an anonymous pipe connected directly to tee
. This symmetrical treatment is a little cleaner, though.)
Upvotes: 3