'Forwarding traffic from port ttyS3 to ttyUSB0 - input/output error

I am attempting to set up a basic pipe that'll transfer all data written to ttyS3 to ttyUSB0. I found a few solutions to the problem such as this, but they don't seem to help much. The issue seems to be that anytime I do anything with ttyS3, I get this:

stty: /dev/ttyS3: Input/output error

Doing ls -l /dev/ttyS* and the same for /dev/ttyUSB* I get the following:

root@arm-64:~# ls -l /dev/ttyS*
crw-rw---- 1 root dialout 4, 64 Feb  9 13:08 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Feb  9 13:08 /dev/ttyS1
crw--w---- 1 root tty     4, 66 Feb  9 13:08 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Feb  9 13:08 /dev/ttyS3
crw-rw---- 1 root dialout 4, 68 Feb  9 13:08 /dev/ttyS4
root@arm-64:~# ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0 Feb  9 13:08 /dev/ttyUSB0

I've created the following script to do the job for me at startup. I changed the major/minor values to match that of USB0 after reading somewhere that this could work as a pipe. Although it does execute without throwing an Input/output error, it doesn't seem to work as intended.

#!/bin/bash
rm /dev/ttyS3
mknod -m 666 /dev/ttyS3 c 188 0
chown root.dialout /dev/ttyS3
chmod 666 /dev/ttyS3
stty -F /dev/ttyUSB0 speed 115200 cs8
stty -F /dev/ttyS3 speed 115200 cs8
cat /dev/ttyS3 > /dev/ttyUSB0 &

I just need to create a basic pipe that'll take all data written to ttyS3 and pass it on to ttyUSB0. Although I don't think it's relevant, I'm running Armbian bullseye on a TV box (Tx3 Mini)



Solution 1:[1]

I just need to create a basic pipe that'll take all data written to ttyS3 and pass it on to ttyUSB0

Don't see a problem so long as each serial terminal is properly setup and functional/operational. Before you create the "pipe", did you verify that each serial terminal is operating properly?

On a SBC I have the console on a serial terminal, and established two more serial terminals using a SoC USART and a USB adapter:

# ls -l /dev/tty*S*                                      
crw-rw---- 1 root dialout 246,  0 Jan  1  2012 /dev/ttyGS0                      
crw------- 1 root tty       4, 64 Jul 31 22:46 /dev/ttyS0                       
crw-rw---- 1 root dialout   4, 65 Jul 31 22:25 /dev/ttyS1                       
crw-rw---- 1 root dialout 188,  0 Jul 31 22:28 /dev/ttyUSB0                     
#

Note that the udev daemon created these device nodes, and no funny business (i.e. manual re-creating device nodes) was necessary to accomplish the "pipe".

To remove canonical processing, each serial terminal is put in raw mode and with matching baudrates:

# stty raw 115200 -F /dev/ttyUSB0
# stty raw 115200 -F /dev/ttyS1

A report of all termios settings:

# stty -aF /dev/ttyUSB0                                  
speed 115200 baud; rows 0; columns 0; line = 0;                                 
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;           
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;  
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;                       
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts                 
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
-iuclc -ixany -imaxbel -iutf8                                                   
-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt   
echoctl echoke -flusho -extproc                                                 
#

# stty -aF /dev/ttyS1                                    
speed 115200 baud; rows 0; columns 0; line = 0;                                 
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;           
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;  
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;                       
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts                 
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
-iuclc -ixany -imaxbel -iutf8                                                   
-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt   
echoctl echoke -flusho -extproc                                                 
#

Then when the command

# cat /dev/ttyS1 > /dev/ttyUSB0 &

is issued, whatever is typed on the remote terminal-emulator program connected to /dev/ttyS1 shows up on the remote terminal-emulator program connected to /dev/ttyUSB0.
This seems to behave like the desired "basic pipe that'll take all data written to ttyS? and pass it on to ttyUSB0".

Bottom line:
Unable to duplicate problems, and can create "pipe" of two serial links.

# uname -a                                               
Linux sama5d2-xplained 5.4.81-linux4sam-2020.10 #1 Thu Jan 14 12:54:56 UTC 2021 
armv7l armv7l armv7l GNU/Linux                                                  
#

The issue seems to be that anytime I do anything with ttyS3, I get this:

stty: /dev/ttyS3: Input/output error

... I'm running Armbian bullseye on a TV box (Tx3 Mini)

As previously mentioned, you need to verify that each serial terminal is operating properly.
Since a "TV box" doesn't really need five (!) serial terminals, you might be seeing/creating bogus device nodes that don't have any hardware to access.
Search the system log for the actual hardware that was initialized, e.g. 'dmesg | grep tty'. One of those UARTs might be used to interface to an IR receiver.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1