Application for the serial Com-Server:
TTY-Redirector/Pseudo-TTYs under Linux
Linux applications whose communication with serial devices is limited to local TTYs are made network-capable using a Com-Server and the GPL2 licensed open source tool socat (e.g. bridging long distances, deficient/missing local TTYs etc.). Whereas the Com-Server provides for the hardware-side connection of the serial device to the network, socatprovides virtual TTYs and pseudo-TTTYs on the Linux system and connects them via TCP bi-directionally to the Com-Server over the network.
In many Linux distributions socat can be installed directly using the respective software manager - simply enter socat as the search term.
The homepage of the socat project with download links, information about supported Linux distributions and comprehensive documentation can be found at http://www.dest-unreach.org/socat/ - Suitable Com-Servers can be found here.
The following command creates the pseudo-TTY csTTY1 and redirects it to the Com-Server 10.40.21.18 located in the network:
socat PTY,link=/dev/csTTY1,echo=0,wait-slave TCP:10.40.21.18:8000,retry=5
The keyword PTY first creates the pseudo-TTY with the name csTTY1 in the directory /dev. The associated option echo=0 deactivates the local echo of the TTY. Using wait-slave the TCP connection to the 2nd data channel is not established until the created pseudo-TTY is opened by an application, so that if a TTY is closed, other stations in the network can access the Com-Server and the connected serial device.
The keyword TCP specifies the 2nd data channel, which is connected to the previously created pseudo-TTY. The IP address and the TCP port number of the Com-Server are specified as address parameters. retry=5 specifies the number of connection attempts in case the Com-Server is currently being used by another station.
- The required serial transmission parameters (baud rate, parity, etc.) must be manually configured in advance in the Com-Server setup. No automatic configuration coupled to the parameters of the opening application is possible.
- Via socat created pseudo-TTYs are useful for all applications which communicate with the terminal device only on the level of the serial data lines Rx and Tx. Transmission on the RS232 control lines (RTS, CTS, etc.) is not possible.
- The option used in the above example wait-slave provides a need-based opening of the network connection. At the same time, closing the TTY closes both the network connection to the Com-Server and the socat process, so that a script-based restart may be necessary. In the case of an execution of the socat command coupled to the system start, the procedure varies depending on the Init system of the Linux distro being used.
- A character-oriented test of the virtual TTY can also be performed using the socat. The following command creates a transparent connection between STDIN/STDOUT of the Linux system and the Com-Server through the pseudo-TTY csTTY1:
socat STDIO,raw,echo=0,escape=0x03 /dev/csTTY1,raw,echo=0