4

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.

Ludefice
  • 45
  • 1
  • 6

1 Answers1

2

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.

nsilent22
  • 2,763
  • 10
  • 14
  • Both of these suggestions worked to get the data piped from one port to the other, however at the other end where I am receiving the data it is coming in one line followed by a blank line repeatedly. Is it possible to log the data that I am transferring from port to port using cat or dd? Is there an option I can add to stop these blank lines from being sent? – Ludefice Jul 24 '15 at 13:48
  • Try using `tee` command: `cat /dev/ttyS0 | tee logfile.log > /dev/ttyS1`. Compare logfile.log with what has been received. Also make sure your tty settings are correct. – nsilent22 Jul 24 '15 at 13:54
  • Looks like the receiver is receiving all of the data, but for whatever reason extra lines are being added either upon transmission or at the receiver. On the transmitter side logfile.log the data does not have any extra blank lines in it. Thanks for your help! – Ludefice Jul 24 '15 at 14:40
  • 1
    Did you set your ttys to be 'raw'? Try: `stty -F /dev/ttySnum raw -echo speed`, where 'speed' is e.g. 19200 and 'num' is serial port number (0, 1 etc.). – nsilent22 Jul 24 '15 at 16:24
  • Yes I tried that but I didn't have any luck...I think it may be a configuration issue that has nothing to do with the radios or the piping. I'll let you know if I suspect that is not the case though. – Ludefice Jul 24 '15 at 17:30
  • 2
    @Ludefice you don't have a config. issue. The same happens here on my terminal; Socat is the way to go but the manpage comes straight from hell. – Wyatt Ward Jan 29 '16 at 01:20