Search code examples
linuxbashserial-portsocat

Pipe One Serial Port to Another in Linux


I am looking for a means to pipe one serial ports data (regardless of data type) to another serial port. In my case I am trying to take in data from one serial port and output it through a radio connected to another serial port in real time.

I already know what ports I am using and have looked up a program called socat, which should be able to handle it but there are no examples of how to do this and I have not been able to figure out how to do it.

Has anybody been able to use socat or a bash scipt/some other method to accomplish this in Linux??

I am running Ubuntu 14.04.


Solution

  • Assuming the serial port you are reading from is /dev/ttyS0, and the other you are writing to (where the radio is connected) is /dev/ttyS1 you shall simply do:

    cat /dev/ttyS0 > /dev/ttyS1
    

    or

    dd if=/dev/ttyS0 of=/dev/ttyS1 bs=1
    

    Of course before you should set all the serial ports' parameters using stty command.